lip9000 Posted March 4, 2009 Share Posted March 4, 2009 I want to get a certain string that lies between two other strings. For example I want to extract Lipari-TV out of the following string: <embed width="563" height="266" type="application/x-shockwave-flash" flashvars="channelId=67365&brandId=1&channel=#Lipari-TV&server=chat1.ustream.tv" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.ustream.tv/IrcClient.swf" allowfullscreen="true" /> I think it would be something to do with preg_match but I have no idea how to write it, something that would get the value between channel=# and &server Link to comment https://forums.phpfreaks.com/topic/147868-how-to-get-the-string-between-two-other-strings/ Share on other sites More sharing options...
sasa Posted March 4, 2009 Share Posted March 4, 2009 try <?php $test = '<embed width="563" height="266" type="application/x-shockwave-flash" flashvars="channelId=67365&brandId=1&channel=#Lipari-TV&server=chat1.ustream.tv" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.ustream.tv/IrcClient.swf" allowfullscreen="true" />'; $start = strpos($test, 'channel=#')+9; $end = strpos($test, '&server='); echo substr($test, $start, $end - $start); ?> Link to comment https://forums.phpfreaks.com/topic/147868-how-to-get-the-string-between-two-other-strings/#findComment-776088 Share on other sites More sharing options...
lip9000 Posted March 4, 2009 Author Share Posted March 4, 2009 try <?php $test = '<embed width="563" height="266" type="application/x-shockwave-flash" flashvars="channelId=67365&brandId=1&channel=#Lipari-TV&server=chat1.ustream.tv" pluginspage="http://www.adobe.com/go/getflashplayer" src="http://www.ustream.tv/IrcClient.swf" allowfullscreen="true" />'; $start = strpos($test, 'channel=#')+9; $end = strpos($test, '&server='); echo substr($test, $start, $end - $start); ?> This is pretty much exactly how I had it originally, but the problem is that every users Channel name is different, so the character lengths vary for each user, it would be good if they were all the same length, that's why I need something that will get everything inbetween channel=# and &server Link to comment https://forums.phpfreaks.com/topic/147868-how-to-get-the-string-between-two-other-strings/#findComment-776096 Share on other sites More sharing options...
lip9000 Posted March 4, 2009 Author Share Posted March 4, 2009 Actually, my bad, it seems to work no matter how long the length is..., even if i change it to Lipari-TV-and-this-is-extra, sure enough it echos the entire world. Hrmmm Link to comment https://forums.phpfreaks.com/topic/147868-how-to-get-the-string-between-two-other-strings/#findComment-776098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.