Why doesn't this Regular Expression work?
I want to get the cont开发者_JS百科ent in the <title>...</title>
of html label. I used the following code, but it doesn't work.
<?php
$content = "<title>";
preg_match_all("/<title>/",$content,$title);
echo $title[0][0];
?>
how to get the get the content in the <title>...</title>
in php.
Are you trying to access the DOM, as you would in JavaScript? You can't do that in PHP unless you're reading an existing HTML page, or you're using output buffering on the page that PHP is generating.
In this case you could use:
<?php
$content = $the_entire_html_page_loaded_from_somewhere;
preg_match( '/<title>(.*)<\/title>/', $content, $title );
print_r( $title );
?>
精彩评论