zahraj zahraj - 5 months ago 23
PHP Question

How can I check in a string exist specific tag or no?

How can I check by php that in a string exist specific iframe tag like below but with another src.

<iframe src="http://www.aparat.com/video/video/embed/videohash/yGmPN/vt/frame" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" height="360" width="640" ></iframe>

Answer

Use the strpos() function to look for the beginning <iframe tag:

<?php
$string = '<iframe src="http://www.aparat.com/video/video/embed/videohash/yGmPN/vt/frame" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" height="360" width="640" ></iframe>';
$test = strpos($string,'<iframe');
if (!empty($test)) {
echo 'That has an iframe!!';
} else {
echo 'There's no iframe in there...';
}
?>

Likewise, you can use this function to search for each parameter you're interested in finding.

strpos() will return the position of the searched-for value in the string if found, or FALSE if not found.

http://php.net/manual/en/function.strpos.php