Reguler Expression for finding “href’s” value:

Lets take a string

$content = "Test <a href=\"http://www.testone.com\">Test Link</a> Tedst <a href=\"http://www.testdone.com\">Testd Link</a> ";

We will use follwing reguler expression to find href's values

$regex_pattern = "/<a href=\"(.*)\">(.*)<\/a>/";

Matching the string with reguler expression, we get it on $matches[1] place.
So complete code is... 

<?php 
$content = "Test <a href=\"http://www.testone.com\">Test Link</a> Tedst <a href=\"http://www.testdone.com\">Testd Link</a> ";
$regex_pattern = "/<a href=\"(.*)\">(.*)<\/a>/"; preg_match_all($regex_pattern,$content,$matches);


print $matches[1];


?>

Comments

Popular posts from this blog

How to Reset Root Password in Drupal 7 with phpMyAdmin

Drupal - Hiding field group and its Children