sandy1028 Posted October 21, 2010 Share Posted October 21, 2010 I have the variables $cap and $url If the $cap contains any of the strings ".jpg,.JPG,.gif,GIF" I have to concatenate $url.$cap Link to comment https://forums.phpfreaks.com/topic/216455-check-and-concatenate/ Share on other sites More sharing options...
mattal999 Posted October 21, 2010 Share Posted October 21, 2010 It's pretty simple really. I'm going to give you an answer in the form of code, but your "question" really is more of a statement. I would work on that if I were you. $imagetypes = array(".gif", ".jpg"); foreach($imagetypes as $type) { if(stripos($cap, $type) !== false) { // Use stripos for case insensitivity, or you could use strtolower($cap) in PHP4 $new = $url.$cap; } } Link to comment https://forums.phpfreaks.com/topic/216455-check-and-concatenate/#findComment-1124808 Share on other sites More sharing options...
AbraCadaver Posted October 21, 2010 Share Posted October 21, 2010 Just for fun: $imagetypes = array(".gif", ".jpg"); if(in_array($cap, $imagetypes) || in_array($cap, array_map('strtoupper', $imagetypes))) { $url .= $cap; } //or if(in_array($cap, array_merge($imagetypes, array_map('strtoupper', $imagetypes)))) { $url .= $cap; } Link to comment https://forums.phpfreaks.com/topic/216455-check-and-concatenate/#findComment-1124891 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.