Jump to content

How to get the string between two other strings?


lip9000

Recommended Posts

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

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);
?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.