php - How to get the specific string from the HTML tag code and check existence of tag in a string? -



php - How to get the specific string from the HTML tag code and check existence of <img> tag in a string? -

i've 2 html codes. 1 of them going nowadays in variable $text follows :

//first html code $text = <a class="comment_attach_file_link" href="https://www.filepicker.io/api/file/vuhoz3n8toyvqudq03zi">vuhoz3n8toyvqudq03zi</a> <a class="comment_attach_file_link_dwl" href="https://www.filepicker.io/api/file/vuhoz3n8toyvqudq03zi">download</a>; //second html code $text = <a title="" href="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws"><img src="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws" height="150px" width="150px"></a> <a href="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws" class="comment_attach_image_link_dwl">download</a>;

if first html code nowadays variable $type should contain value 'file' $type = 'file';

if sec html code nowadays variable $type should contain value 'image' $type = 'image';

i want accomplish using html parsing.

in first case, want string 'file' class attribute of first anchor tag class="comment_attach_file_link"

in sec case, want string 'image' if <img> tag nowadays in html code.

how should in efficient way in php? please help me.

thanks.

you can utilize strpos() that:

<?php $text = '<a title="" href="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws"><img src="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws" height="150px" width="150px"></a> <a href="https://www.filepicker.io/api/file/xda3udwdtwydvk7islws" class="comment_attach_image_link_dwl">download</a>'; if (strpos($text,'class="comment_attach_file_link"') !== false) { echo 'file'; } elseif (strpos($text,'<img') !== false) { echo 'image'; } ?>

php html dom html-parsing

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -