MyBB Central

Full Version: Need help with hyperlinks in php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello! I am trying to learn php and I am trying to make a comments script. I have a html form where user will enter Name, Email, Website and Comments. This Data will be stored in mysql. I want to make the Name a hyperlink pointing towards the Website url entered by the user. Script is doing everything fine but it makes the link look something like this:
http;//wwww.myowndomain.com/http;//www.urlgivenbyuser.com I am pasting the code here. Kindly someone take a look and guide me.

$username= $results[$i]['Name'];
$weburl= $results[$i]['Website'];
$newurl = str_ireplace("http://localhost/try/","","$weburl");

$output = "<a href=\"$newurl\" target=\"_blank\">$username</a>". " said:"; ?>
<div class="name"><?php echo $output; ?> </div>
Nobody is willing to help????Sad
If $weburl is the website that the user is given, then why not do replace $newurl with $weburl in the link tag?

I'm not entirely sure what the purpose of this line is?:

Code:
$newurl = str_ireplace("http://localhost/try/","","$weburl");
Problem has been solved the problem was with http:// if the user post url with http:// everything goes fine but when don't link starts to point toward current domain. Here is the final working code:

$username= $results[$i]['Name'];
$url = $results[$i]['Website'];
$add = "http://";
$check_url = substr($url,0,7);
if($check_url=="http://") {
$output = "<a href=\"{$url}\">$username</a> said:". "<BR>";
}
else {
$url = ($add.$url); }
$output = "<a href=\"{$url}\">$username</a> said:". "<BR>";

Thanks for replying Smile