Forum Moderators: coopster

Message Too Old, No Replies

If Domain Is Found Do Nothing Else Add Domain

         

Ben_Shelock

2:54 am on Feb 22, 2009 (gmt 0)

10+ Year Member



Right, a user submits a URL. But there is not always a domain on the front. I want to add the URL to this string.

Ive done this, but it inevitably doesn't work. Could someone tell me what ive done wrong please

<?php
$url = 'something.html';
$target_url = 'http://www.google.com';
if(preg_match($target_url, $url, $new)) {
if(count($new) > 0) {
$url = $target_url.$url;
}
}
echo $url;
?>

epohcj

4:42 am on Feb 23, 2009 (gmt 0)

10+ Year Member



Try this

<?php
$url = 'something.html';
$target_url = 'http://www.google.com';
if (stristr($url, $target_url) === true){
$url = $target_url.$url;
}
echo $url;
?>