Menu
Is there anyway (i know there is, or so Im pretty sure) to grab all the URLs in a $var, and change the URLs?
lol
thanks
[code=php]
$new_var = preg_replace('/http:www.whatever.com/', $new_url, $var);
[/code]
[URL=http://us3.php.net/manual/en/function.preg-replace.php]http://us3.php.net/manual/en/function.preg-replace.php[/URL]
check out the link for the function preg_replace
it takes a pattern and replaces it, assuming you know the address you want to change you could do something like:
[code=php]
$new_var = preg_replace('/http:www.whatever.com/', $new_url, $var);
[/code]
Although like SpectreReturns said, you're a bit vague and I'm not sure if this is exatly what you want[/QUOTE]
[CODE]<A href="http://me.com/downloads.php">CLICK MEEE!!</a>[/CODE]
[CODE]<a href="http://mysite.com/url=me.com/downloads.php">CLICK MEEE!</a>[/CODE]
[code=html]<a href="http://www.yoursite.com/redirect.php?url=downloads.php">visit my downloads section</a>[/code]
<?php
$goto = "http://www.yoursite.com/".$_GET['url'];
if( substr($goto, 0, 24) == 'http://www.yoursite.com/')
{
header("Location: $goto");
}
else
{
header("Location: http://www.yoursite.com/"); // goes to your home page
//header("Location: ".$_SERVER['HTTP_REFERER']); // goes to previous page
//die("an error has occured. please do not tamper with the urls.");
}
?>
[code=html]<a href="redirect.php?url=accessjdm.com">JDM's Website</a>[/code]
<?php
$goto = "http://".$_GET['url'];
header("Location: $goto");
?>
[code=php]ereg(""([^"]*).com", $data, $links);
$data = preg_replace($links[1], "http://mysite.com/file.php?url=$links[1]", $data);
[/code]
Okay, so you grab the data from a file and then use a RegExp to find and replace all of the instances of every link with a link to a certain page. You've got the basic idea, so are you looking for the RegExp to do it, or the php code, or both?[/QUOTE]
[code=php]
$data = "<a href="http://something.com">Something</a>n<br>n<a href="http://somethingelse.com">Something Else</a>n<br>"; // A sample data variable
$reg = "<a href="([^"><]+)">([^<>]+)</a>"; // Your RegExp
$replace = "<a href="http://whatyouwant.com">What You Want</a>"; // The code to the link you want to replace it with
$test = ereg_replace($reg, $replace, $data); // A call to ereg_replace(), you can use preg_replace if your server supports it
[/code]
[code=php]<?php
$data = '<a href="http://www.google.com">google</a>
<iframe src="http://domain.com/path/to/nowhere">
</iframe>
';
if(preg_match_all("/(?:href|src)=["']?([^"'<>]+)["']?/", $data, $m))
{
$m = $m[1];
foreach($m as $u)
{
$u = rawurlencode($u);
echo "<a href="redirect.php?url=$u">link</a><br>n";
}
}
?>[/code]
0.1.9 — BETA 5.19