简体   繁体   中英

PHP check string for html

$content gives the html code like:

<p>text</p>
<p><img ... /></p>
<div class="video">...</div>

or just

<p>text</p>
<p>more text</p>

Also we have a variable:

$video_match = false;

We should turn $video_match to true , if <div class="video"> (exactly this code) exists in $content .

Thanks.

Use:

if (strpos($content, '<div class="video">') !== FALSE)
{
  $video_match = true;
}

More Info:

Update:

Or more compact version as shown in the comments below:

$video_match = (strpos($content, '<div class="video">') !== FALSE);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM