Jump to content

regEx and simple_html_dom to extract a visible text in an anchor tag


kevinkhan

Recommended Posts

I want to extract the name within the anchor tag of the following code takin from a source file.

 

Has worked at <a href="http://www.facebook.com/pages/Bridewell-bar/110926698934250" data-hovercard="/ajax/hovercard/page.php?id=110926698934250">Bridewell bar</a>

 

is there anyway i can remove all the code before "Has worked at" and use the code below to extract the name

 

$page is full source code of page

 


include('simple_html_dom.php');

code to remove every thing before "Has worked at"

$job = str_get_html($page);
$job = $jobd->find(' next <a> tag',0);
$job = $job->value;

 

Any ideas and can somebody help me write the code.

 

iv tryed using strpos function but can figure it out :(

Link to comment
Share on other sites

Hi,

Try use this example:

$str = 'SOme contennt - Has worked at <a href="http://www.facebook.com/pages/Bridewell-bar/110926698934250" data-hovercard="/ajax/hovercard/page.php?id=110926698934250">Bridewell bar</a>';
$regxp = '/Has worked at \<(.*)\>(.*?)\</i';
if(preg_match($regxp, $str, $re)) {
  echo $re[2];           // Bridewell bar
}

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.