Jump to content

Need Help Extracting Data From String


gaza165

Recommended Posts

I have a string

 

<p>Bollywood romcom: a pair of wouldbe suicides choose the same bridge at the same time.</p><p><a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a> (<a href="http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66" target="_blank">www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66</a>), Ozone Leisure Park, Grenoble Road (next Kassam Stadium), Oxford OX4 4XP; Tel. 08712 240 240 (10p per min from BT).<br /> </p>

 

Using php i want to extract

 

http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66

 

from the <a> tag.

 

I have already tried using

 

    
<?php

$pattern = "/<a href=\"([^\"]*)\">(.*)<\/a>/iU";
preg_match_all($pattern, $link, $matches);
var_dump($matches);
?> 

 

The output I get is

 

array

  0 =>

    array

      0 => string '<a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a>' (length=81)

  1 =>

    array

      0 => string 'http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema' (length=56)

  2 =>

    array

      0 => string 'Vue Cinema' (length=10)

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/215060-need-help-extracting-data-from-string/
Share on other sites

Try this... its will probably only work in this string or string very similar...

<?
$string = '<p>Bollywood romcom: a pair of wouldbe suicides choose the same bridge at the same time.</p><p><a href="http://www.dailyinfo.co.uk/reviews/venue/1320/Vue_Cinema">Vue Cinema</a> (<a href="http://www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66" target="_blank">www.myvue.com/cinemas/index.asp?SessionID=0D86903A19334C93A7491563A77862A3&cn=1&ln=1&ci=66</a>), Ozone Leisure Park, Grenoble Road (next Kassam Stadium), Oxford OX4 4XP; Tel. 08712 240 240 (10p per min from BT).<br /> </p>';

$string = explode('<a href="',$string);
$string = explode('" target',$string[2]);

echo $string[0];
?>

 

Tell me how it goes, also if you are wanting to do multi strings you should use preg_replace

 

Regards, Paul.

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.