This works but i dunno how what to put in the parse function for example:
Main Code:
PHP Code:
<?php
function parse($html, &$title, &$text, &$anchors)
{
$pstring1 = "'[^']*'";
$pstring2 = '"[^"]*"';
$pnstring = "[^'\">]";
$pintag = "(?:$pstring1|$pstring2|$pnstring)*";
$pattrs = "(?:\\s$pintag){0,1}";
$pcomment = enclose("<!-", "-", "->");
$pscript = enclose("<script$pattrs>", "<", "\\/script>");
$pstyle = enclose("<style$pattrs>", "<", "\\/style>");
$pexclude = "(?:$pcomment|$pscript|$pstyle)";
$ptitle = enclose("<title$pattrs>", "<", "\\/title>");
$panchor = "<a(?:\\s$pintag){0,1}>";
$phref = "href\\s*=[\\s'\"]*([^\\s'\">]*)";
$html = preg_replace("/$pexclude/iX", " ", $html);
if ($title !== false)
$title = preg_match("/$ptitle/iX", $html, $title)
? $title[1] : '';
if ($text !== false)
{
$text = preg_replace("/<$pintag>/iX", " ", $html);
$text = preg_replace("/\\s+| /iX", " ", $text);
}
if ($anchors !== false)
{
preg_match_all("/$panchor/iX", $html, $anchors);
$anchors = $anchors[0];
reset($anchors);
while (list($i, $x) = each($anchors))
$anchors[$i] =
preg_match("/$phref/iX", $x, $x) ? $x[1] : '';
$anchors = array_unique($anchors);
}
}
function enclose($start, $end1, $end2)
{
return "$start((?:[^$end1]|$end1(?!$end2))*)$end1$end2";
}
echo parse("http://www.bbc.co.uk","","","");
?>
PHP Code:
<?php echo parse("http://www.bbc.co.uk","","",""); ?>
I tried that but got this error
Fatal error: Only variables can be passed by reference in
/home/champion/public_html/test/test/index.php on line
49
I dunno what the $title, $text, $anchors is meant to be?
http://www.php-development.ru/php-sc...tml-parser.php