Jump to content

Constructing a url from two strings


greenheart

Recommended Posts

Try this, I know it looks different this what you are used to, but it is highly optimized and will work great. 

 

Notes: 

  • echo is slightly faster than print in PHP because echo does not return a value.
  • The commas are an alternate way to write echo statements, which are faster to process.
  • Single quotes are faster than double quotes for PHP to process, because it has to check for variables in double quotes.
  • You don't have to escape single quotes used inside of double quotes, and you don't have to escape double quotes used inside of single quotes.

 

 

echo "<a href='", $string, "'><b>", $string2, "</b></a>";

 

EDIT: You will want to use the following code instead to take advantage of the quote trick :)

 

echo '<a href="', $string, '"><b>', $string2, '</b></a>';

<?php
$link = www.example.com 
echo '<a href="' . $link. '"><b>' .$link. '\n';
}
?>  

 

$link = "www.example.com";  <-- quotes and terminator, that fixes your error.

 

Try just: echo "<a href='$link'><b>$link\n";  You can just use variables in your strings as long as you use double quotes.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.