I have used special characters removing code but I can not return from this code. How can I return from this code? My code
$removeme = array("=", "+", " ", ",", "-", "_", "$", "^", "&");
$title = str_replace($removeme , "-", $row['title']);
I used in url link the following.
href="view-items-details?ID=<?php echo $row['sl'];?>&show=<?php echo $title;?>"
And using GET method I called it the following.
$id=$_GET['ID'];
$id2=$_GET['show'];
$removeme = array("=", "+", " ", ",", "-", "_", "$", "^", "&");
$id1 = str_replace("-", $id2, $removeme);
And my database query
$SQL="select * from tb_classified where sl='$id' and title='$id1'";
$obj->sql($SQL);
while($row = mysql_fetch_array($obj->result))
But my post doesn't appear. Can anyone see what have I wrong?
You have a bit of a problem here:
$id=$_GET['ID'];
$id2=$_GET['show'];
$removeme = array("=", "+", " ", ",", "-", "_", "$", "^", "&");
$id1 = str_replace("-", $id2, $removeme);
$id1
will be an array, because the "subject", $removeme
, is an array. Basically, it will be equal to ['=', '+', ' ', ',', "$id2", '_', '$', '^', '&']
(the result of replacing '-'
with $id2
for each element). And an array stringifies as "Array"
.
Slightly closer to correct would be $id1 = str_replace("-", $removeme, $id2);
-- but the very idea still has a serious flaw that will prevent it from ever working correctly.
I'm not exactly sure what you're trying to accomplish here. But when you turn multiple characters into the same thing, you lose information. Without the original string, you can't "unreplace" them -- the info that'd let you do so is now gone. The chars are dashes now, and don't remember what they used to be.
(That's why i recommend not mangling data in this fashion. It'd be better to encode or escape the data wherever possible...and it's nearly always possible.)
(This section assumes you're trying to find rows where the title
, once cleaned up, would match $_GET['show']
.)
In the short term, you could change the dashes to underscores and say title like '$id1'
rather than title = '$id1'
. The underscore is a wildcard character when used with like
, so you'd find any title with any character in those spots, as long as the other chars matched too. But of course that's less specific than an exact match, and would also make it hard for MySQL to use any indexes on title
.
Alternatively, if sl
is actually an ID as the form param name suggests, then perhaps you don't need the title at all to identify the record...