I need to remove these ' & ' characters from each property of a php object
I tried the code below but it's not working...what am I missing?
thanks dudes
foreach($query_item as $key => $value)
{
$key = str_replace(' & ',' & ',$value);
}
I need to remove these ' & ' characters from each property of a php object
I tried the code below but it's not working...what am I missing?
thanks dudes
foreach($query_item as $key => $value)
{
$key = str_replace(' & ',' & ',$value);
}
You should refer to $value by reference, and modify it in place:
foreach($query_item as $key => &$value)
{
$value = str_replace(' & ',' & ',$value);
}
The alternative would be to reference the item within the object using $key:
foreach($query_item as $key => $value)
{
$query_item->$key = str_replace(' & ',' & ',$value);
}
I'll also point out htmlentities(), while we're on the subject of replacing & with &.
this&that.