Jump to content

Geting the regular expression from both the URL and the script.


strago

Recommended Posts

<?php
$user = $_GET['user'];
$request_url ="http://www.domain.com/logs.shtml";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

//THIS NEEDS CHANGED!!!!!
$regex='|$user - (.*?) - $user|';

preg_match_all($regex,$result,$parts);
$logs=$parts[1];
foreach($logs as $log){
	echo "<B>".$log."</B><br>";
}
curl_close($ch);
?>

 

The logs file looks like

 

username - log info - log info - log info - username

 

For a URL like

 

http-//www.domain.com/view-logs.php?user=strago

 

I want it to spit out just the lines from the log file that got

 

strago - log info - log info - log info - strago

single quotes indicate a literal string, and there is no variable substitution. you'll need double-quotes, or concatenation

 

$regex='|$user - (.*?) - $user|';
echo "regex: $regex";

 

output

regex: '|$user - (.*?) - $user|'

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.