i have following code but unable to get full variable values on return.
<?php
$no7="Girls pink";
$no8="All Categories";
$aw="2";
echo'<table width="auto" border="0">
<tr>
<td width="auto" class="s">'; echo "<a href=search.php?search_name=".$no7."&mydropdown=".$no8."&pno=".$aw.">".$aw."</a>"; echo'</td>
</tr>
</table>';
?>
Thanks for help Regards,
Use urlencode and htmlspecialchars:
echo "<a href='search.php?search_name=" . urlencode($no7) . "&mydropdown=" . urlencode($no8) . "&pno=" . urlencode($aw) . "'>" . htmlspecialchars($aw) . "</a>";
Also: add quotes around the URL, and replace &
with &
for better HTML syntax.
Add quotes on href
value:
echo "<a href='search.php?search_name=".$no7."&mydropdown=".$no8."&pno=".$aw."'>".$aw."</a>";
// ^--------------------------- quotes ----------------------------^
Clean up the horrible formatting/layout and use a HEREDOC:
echo <<<EOL
<table width="auto" border="0">
<tr>
<td width="auto" class="s"><a href="search.php?search_name={$no7}&mydropdown={$no8}&pno={$aw}">{$aw}</a></td>
</tr>
</table>
EOL;
Note how the HEREDOC removes the need for all those individual echoes, allows for variable interpolation into the string (no more 'break out of string to concatenate'), and allows for proper formatting/indentation of the HTML code.
The problem is the spaces in your variables. It's more of an issue with browsers interperting spaces as the end of your href tag. As suggested earlier, use urlencode
or convert the spaces in your variables to +