I need a help here, There's an error every time I add a link in my php file.
Example:

<php
$link = "twitter.com";
echo "<a href = '".$link."'> link </a>";
?>

on click, the address would be change on "http://localhost/project/twitter.com" whch is supposed to be "twitter.com"
I've tried placing

<?php
$link = "twitter.com";
echo "<a href = '../../".$link."'> link </a>";
?>

but still it doesn't work. $link is stored in the database.
I'm new here. Please help me.

try like this

$link = "www.twitter.com";
<a href ="<?=$link?>"> link </a>

That happens because if you don't put a protocol in a link it will be interpreted as a subdirectory so if you want to make an external link you should put

http://|https://|ftp://

etc so in your case it would be

$link = "http://www.twitter.com";
<a href ="<?=$link?>"> link </a>
Member Avatar for rajarajan2017

You can try these kind of things without www. or http:// in your browser but not with the codes, code strictly first refers to your local. So that only it retrieves your php localhost and tried from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.