On Thu, 26 Aug 2004 09:41:28 +0530, in php.general [EMAIL PROTECTED]
(Syed Ghouse) wrote:

>Will anybody tell me how to extract the value (say Google)
> from the code below:
>
><a href="www.google.com">Google(value to extract)</a>

Instead of using regular expressions (and taking care of all
exceptions), you might want to use xml_parser_create(), since you
essentially want to parse the contents of a tag. I simply don't think
that regular expressions is the right tool here (and the complexity of
the regular expression when all exceptions has been taken care of is
unnecessary).

Works fine under PHP4 and PHP5:

<?php
$string =
'<a href="doc.php?id=13" target="_blank" title="go go go">blabla</a>';

$x = xml_parser_create();
xml_parse_into_struct($x,$string,$array);
// href will be available in $array[0]['attributes']['HREF']
?>

If you are curious, you could add:

<?php
print "<pre>";
var_dump($array[0]['attributes']);
print "</pre>";

print "<hr>";

print "<pre>";
var_dump($array);
print "</pre>";
?>


But look at $array[0]['attributes']['HREF'] for the link.

-- 
- Peter Brodersen

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to