I'm having trouble with my foreach
loop.
On my script:
$Tags = "PHP,HTML,CSS,Java";
$ExplodedVar = explode(",", $Tags);
print_r($ExplodedVar);
foreach ($ExplodedVar AS $NewStr)
{
echo "<a href='#>$NewStr</a>,";
}
The print_r($ExplodedVar);
Is displaying the correct output of:
Array ( [0] => PHP [1] => HTML [2] => CSS [3] => Java )
foreach
loop outposts only HTML & Java
You missed the close quote '
of href.
foreach ($ExplodedVar AS $NewStr)
{
echo "<a href='#'>$NewStr</a>,";
}
And if the data is user input, then you need to sanitize the data.
foreach ($ExplodedVar AS $NewStr)
{
echo "<a href='#'>". htmlspecialchars($NewStr)."</a>,";
}
You miss one single quote on hash :
echo "<a href='#'>$NewStr</a>,";