74 lines
3.2 KiB
PHP
74 lines
3.2 KiB
PHP
|
<form action='testregexp.php' method='post' name='testpregexp'>
|
||
|
<input name='modulepage' value='commentnews' type='hidden'></input>
|
||
|
URL <input name='url' type='text' size='30' value='<?php echo $_REQUEST["url"] ?>'></input><br />
|
||
|
Regexp <input name='regexp' type='text' size='30' value='<?php echo $_REQUEST["regexp"] ?>'></input><br />
|
||
|
<input name='Ecrire' value='Test!' type='submit' />
|
||
|
</form>
|
||
|
<?php
|
||
|
$grep=$_REQUEST["regexp"];
|
||
|
$url=$_REQUEST["url"];
|
||
|
if (!file_exists("../tmp/regexptest.tmp"))
|
||
|
{
|
||
|
echo "writing ../tmp/".$url."...";
|
||
|
$file=file($_REQUEST["url"]) or die("<b>Unable to load URL!</b>");
|
||
|
$data=implode($file);
|
||
|
$cache = fopen("../tmp/regexptest.tmp","w");
|
||
|
fwrite($cache, $data);
|
||
|
fclose($cache);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
echo "file ../tmp/".$url." already exists in cache, using it.";
|
||
|
$data=file("../tmp/regexptest.tmp");
|
||
|
}
|
||
|
echo "applying $grep...";
|
||
|
preg_match_all($grep,$data,$res,PREG_SET_ORDER);
|
||
|
print_r($res);
|
||
|
|
||
|
$index = 1;
|
||
|
foreach ($res as $elt)
|
||
|
{
|
||
|
if ($elt[1] != "" && $elt[2] != "")
|
||
|
{
|
||
|
$niouzes[$index]["link"] = $elt[1];
|
||
|
if (file_exists($baseurl.$elt[1]))
|
||
|
{
|
||
|
$dataitem = implode("",file($baseurl.$elt[1]));
|
||
|
$dataitem = strtr($dataitem,"\n\0\r"," ");
|
||
|
$dataitem = trim($dataitem);
|
||
|
if (isset($grepitemdate))
|
||
|
{
|
||
|
preg_match_all($grepitemdate,$dataitem,$resitem,PREG_SET_ORDER);
|
||
|
$niouzes[$index]["date"] = $resitem[0][1];
|
||
|
}
|
||
|
else
|
||
|
$niouzes[$index]["date"] = "unknown";
|
||
|
if (isset($grepitemsummary))
|
||
|
{
|
||
|
preg_match_all($grepitemsummary,$dataitem,$resitem,PREG_SET_ORDER);
|
||
|
if (strlen(strip_tags($resitem[0][1])) > 200)
|
||
|
$niouzes[$index]["summary"] = substr(strip_tags($resitem[0][1]), 0, 200)."...";
|
||
|
else
|
||
|
$niouzes[$index]["summary"] = strip_tags($resitem[0][1]);
|
||
|
}
|
||
|
else
|
||
|
$niouzes[$index]["summary"] = "unknown";
|
||
|
if (isset($author))
|
||
|
{
|
||
|
$niouzes[$index]["author"] = $author;
|
||
|
}
|
||
|
else if (isset($grepitemauthor))
|
||
|
{
|
||
|
preg_match_all($grepitemauthor,$dataitem,$resitem,PREG_SET_ORDER);
|
||
|
$niouzes[$index]["author"] = $resitem[0][1];
|
||
|
}
|
||
|
else
|
||
|
$niouzes[$index]["author"] = "unknown";
|
||
|
}
|
||
|
$niouzes[$index]["title"] = trim($elt[2]);
|
||
|
}
|
||
|
echo "<a href='".$niouzes[$index]["link"]."'>".$niouzes[$index]["title"]."</a><br>";
|
||
|
$index++;
|
||
|
}
|
||
|
?>
|