开发者

Why doesn't this Regular Expression work?

开发者 https://www.devze.com 2023-02-09 11:34 出处:网络
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.

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 );
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消