I'm using:
header('Location: palette/'.urlencode(str_replace(' ','_',$title)));
To redirect a user upon submitting a form. This code above replaces %20
(a space) with _
for the title entered.
So instead of the user entering "Great place"
and it trying to send them to a page called palette/Great%20place
it sends them to palette/Great_place
Now my question, is it possible to apply this technique to a hyperlink?
I have the following loop:
<?php
while($row = mysql_fetch_array($result))
{
echo "<a href='palette/$row[title]'><div id='main_col_container'>";
echo "<div class='title'> $row[title]</div>";
echo "<div class='main_color' style='background: $row[color1];'></div>";
echo "<div class='main_color' style='background: $row[color2];'></div>";
echo "<div class='main_color' style='background: $row[color3];'></div>";
echo "<div class='main_color' style='background: $row[color4];'></div>";
echo "<div class='main_color' style='background: $row[color5];'></div>";
echo "</div></a>";
}
?>
The problem with this of course is, $row[title]
represents the original data (it needs to show "Great_place"
, not "Great place"
Just to clarify: Is it possible to str_replace for a hyperlink for the purpose I'm after, if so, how can I go about this?
EDIT: This is what I have got now which is working
<?php
while($row = mysql_fetch_array($result))
{
$titleurl = str_replace(' ','_',$row['title']);
echo "<a href='palette/$titleurl'><div id='main_col_container'>";
echo "<div class='title'> $row[title]</div>";
echo "<div class='main_color' style='background: $row[color1];'></div>";
echo "<div class='main_color' style='background: $row[color2];'></div>";
echo "<div class='main_color' style='background: $row[color3];'></div>";
echo "<div class='main_color' style='background: $row[color4];'></div>";
echo "<div class='main_color' style='background: $row[color5];'></div>";
echo "</div></a>";
}
?>
Is this the best technique for the outcome? Or is it considered bad practise for whatever reason?