I have a sentence in PHP that I’ve broken down into its word components using explode.
foreach ($words as $splitword)
{
echo $splitword;
/* echo "<a href = 'word.php?word=" . $splitword . "'>" . $splitword . "</a>"; */
echo " ";
}
What I want to do is make each word clickable, so I echo each word followed by a space. Now, using the code you see above, everything looks fine and natural. However, if I uncomment the commented line, and comment out echo $splitword;, so that I’m now echoing links instead of just the word, things get ugly:
echo " "no longer works, I have to useecho " "- The spaces are very large. Echoing each word without making it a link produces natural spacing, the way it should be. But when I start using the
atag followed by , the spaces are about twice as wide.
Any idea why, and what a workaround is?
echo " "does not work because you are writing HTML, which does not parse ” “.You’ll have to use
like you already discovered.The extra spacing could be your styling. Check your CSS. If you still don’t find anything strange, add this to your CSS: