s1yman Posted August 28, 2008 Share Posted August 28, 2008 Hi, I managed to confuse myself again. . . I have a script that will pull back results which could be either text or an image (the images are just <img links to the ftp server) I was wondering, is it possible to have an if query that checks if it is an image or text first, something like "if starts with <img..." I googled it but couldn't seem to find anything. Thanks in advance for any & all help. Link to comment https://forums.phpfreaks.com/topic/121706-solved-starts-with-if-query/ Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 if (substr($someString,0,4) == '<img') { // this is an image tag } Link to comment https://forums.phpfreaks.com/topic/121706-solved-starts-with-if-query/#findComment-627815 Share on other sites More sharing options...
obsidian Posted August 28, 2008 Share Posted August 28, 2008 If you truly want to see if it starts with the img tag, use a regular expression: <?php if (preg_match('|^<img|i', $string)) { } ?> This is also case insensitive, in case the string comes back with <IMG for some reason. Link to comment https://forums.phpfreaks.com/topic/121706-solved-starts-with-if-query/#findComment-627832 Share on other sites More sharing options...
s1yman Posted August 28, 2008 Author Share Posted August 28, 2008 Kool - that works perfectly!! thank you!!! Link to comment https://forums.phpfreaks.com/topic/121706-solved-starts-with-if-query/#findComment-627837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.