Jump to content

Recommended Posts

Maybe you should look at str_replace and see what you're doing wrong. Are you trying to just replace a comma? Or a ',' (quotations) as well?

 

str_replace(',' ,  "" , $_SESSION['L_NAME0']);

 

As you're using a $_SESSION variable, why are you removing commas? Are you wanting to explode ?

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985552
Share on other sites

The str_replace() you posted does what you are asking, provided you use it like I stated (edit: and CV just re-quoted for your convenience since you apparently did not see or read the post) -

<?php
$_SESSION['L_NAME0'] = "O'Malley";
$_SESSION['L_NAME0'] = str_replace("'", "", $_SESSION['L_NAME0']);
echo $_SESSION['L_NAME0'];
?>

 

Are you sure you want to remove the single-quotes or do you actually need to escape them? What overall problem are you having that you are trying to solve?

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985557
Share on other sites

The single quote is at the end of the string and str_replace don't work, it'll work if the quote is anywhere else in the string though which is weird. The reason I want to remove the quote is because I am trying to send the data over to the paypal server but the quote causes the paypal server to return an error.

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985559
Share on other sites

You will need to be way more specific about what you are trying that does not work, because the following DOES work with the single-quote at the end of the string -

 

<?php
$_SESSION['L_NAME0'] = "OMalleys'";
$_SESSION['L_NAME0'] = str_replace("'", "", $_SESSION['L_NAME0']);
echo $_SESSION['L_NAME0'];
?>

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985561
Share on other sites

It's either not a single-quote or the first parameter in the str_replace() "'" is not a single-quote.

 

What does this show, when put right after the line that sets $row -

<?php
$arr = str_split($row->name);
foreach($arr as $char){
echo ord($char),'.';
}
?>

 

Also, something unusual is going on with your database, because the \ escape character should not be present in the data in the database (though it could be in the data retrieved if magic_quotes_runtime is ON.)

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985569
Share on other sites

The 39 value is a single-quote. That means that the actual data is correct. That either means that your str_replace() code does not have a single quote in the first paramter (are you using an English keyboard and an ASCII programming editor and type the ' rather than copy/pasted it from somewhere) or your actual code after the str_replace() is adding a single quote.

 

Here is the escape \ story one more time -

 

The \ escape characters must be present in the query string so that special SQL characters, such as a single-quote, don't break the syntax of the query (or allow sql injection.) The \ characters are NOT inserted into the database. If you have \ characters in the database it means that your data was escaped twice. This usually happens if magic_quotes_gpc was ON at the time the data was inserted and your code also escaped the data. If the \ characters are not present in the database (which is correct) but they are present when the data is retrieved by php, that means that magic_quotes_runtime is on and it should simply be turned off in your script.

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985575
Share on other sites

Ah, Ok - I ran the query again on a diff value which also has the single quote at the end of it and this is what it returned:

 

68.97.119.114.97.104.32.68.85.79.32.50.48.49.48.92.38.35.51.57.59.

 

What does 59 translate to ?

 

As for magic quotes, I checked the php.ini file and this is what I found:

magic_quotes_gpc = Off

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985583
Share on other sites

I checked the php.ini file

Always use a phpinfo() statement to check what settings are in case the php.ini that you are looking at is not the one that php is using.

 

59 is a ; (semi-colon) unless that is part of a multi-byte encoded character. It would help if you posted the string that corresponds to.

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985584
Share on other sites

okay well you can clearly (hopefully) count that there are more numbers than there are in that string...if you use chr() instead of ord() or if you rightclick > view source you will see that your string contains

&#39;

instead of '  so at some point in time in your script, it's being encoded.

Link to comment
https://forums.phpfreaks.com/topic/186601-str_replace-problem/#findComment-985592
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.