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; ?> PHP:
What are you using preg_match for? preg_match is for checking if a string matches a regular expression, which isn't how you're using it there. Tell me what you're trying to do with preg_match and I can suggest a substitute.
A user submits a URL. This could be something like http://www.google.com/something.html or just something.html. I need to detect if just something.html has been submitted and if it has I need to change it to http://www.google.com/something.html
How can you add something if you don't know what he's trying to submit ? I can submit something.html, you will add google.com in the front of it .. Why ? Maybe I mean yahoo.com/something.html ..
$target_url has been defined before and is the domain we need to use. $url is the user submitted url. Sorry I didn't explain it well at all
try this <?php $url = 'something.html'; $target_url = 'http://www.google.com'; if(stripos($url, $target_url) === FALSE) { $url = $target_url.$url; } echo $url; ?> PHP: