-
char replace
hi
im trying to change char in a text block but i cant get it to work.
can somone please help
the text is taken of another website and formatted. taking out any links and doubling " and ' so it can be added to my database (mysql)
i got this
PHP Code:
$Temp = strip_tags($plot[1], '<br>');
$Temp2=str_replace('"','""',$Temp);
$plott[1]=str_replace("'","''",$Temp2);
-
Re: char replace
You're going to have to be more descriptive. What are you putting in (value of $plot[1] before your replacement code) and what are you getting out (value of $plott[1] at the end of your code)? You can help yourself troubleshoot by echo'ing out the results each step of the way:
PHP Code:
echo $plot[1] . "\n\n";
$Temp = strip_tags($plot[1], '<br>');
echo $Temp . "\n\n";
$Temp2=str_replace('"','""',$Temp);
echo $Temp2 . "\n\n";
$plott[1]=str_replace("'","''",$Temp2);
echo $plott[1] . "\n\n";
At which point are you not getting what you expected for the output?
-
Re: char replace
hi i solved my problem by using the following
Code:
$Find = array("'",'"');
$ee =$plot[1], '<br>';
$plot[1] = str_replace($Find,"",$ee);
-
Re: char replace
hi
but now i have come across another problem with the same code..
PHP Code:
# Locations
$locs = $movie->locations();
if (!empty($locs)) {
++$rows;
foreach ($locs as $loc) {
if ( empty($loc['url']) );
else ;
}
}
//this is the main txt im trying to filter this is from $ee
//St. Luke's Hospital - 2632 E. Washington Street, Pasadena, California, USA
//---
$Find = array("'",'"');
$ee =$loc['name'];
$locationsname = str_replace($Find,"",$ee);
when i use the txt im trying to filter direct in to the filter for example.
PHP Code:
$ee="St. Luke's Hospital - 2632 E. Washington Street, Pasadena, California, USA";
the filter works but when im using the text direct from $loc['name']; the filter dont work
-
Re: char replace
.. wait. the entire point of all of this is to eventually add this data to the database, correct? don't use str_replace() at all then. use an escape function, like mysql_real_escape_string():
PHP Code:
$mysql_safe_loc = mysql_real_escape_string($loc['name']);
then, use it in your query:
PHP Code:
$sql = "INSERT INTO locations (name) VALUES ('{$mysql_safe_loc}');";
-
Re: char replace
hi kows
i never thought to look at sql code. i have now changed it to the
PHP Code:
mysql_real_escape_string();
and works perfect. it will take me some time to sort the rest of my code to this.
thanks again kows you have been a big help on this as im still learning all this php coding:thumb::thumb::thumb: