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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.