yoyo
yoyo

Reputation: 11

Using stripslashes on a database row php

{$row['info']}

How do I use stripslashes() php function on this?

I've tried : stripslashes({$row['info']}), doesnt work and this: {stripslashes($row['info'])}

Neither work.

Do I have to use a $var first??

Thanks

Upvotes: 1

Views: 796

Answers (4)

jancha
jancha

Reputation: 4967

Your question is somewhat confusing.

stripslashes() takes parameter and converts backslashed symbols to normal ones. more over, it does not affect the parameter. it returns stripped version.

so $result = stripslashes($source) or $row["info"] in your case.

Upvotes: 1

Kalle H. Väravas
Kalle H. Väravas

Reputation: 3615

It almost seems, that you are using heredoc syntax because of your {}. Question, is why? Are you seriously displaying your results like this?:

echo <<<my_results
Info: {$row['info']}
my_results;

Well, since that is cool way to do so then here is your fix:

$row_info = stripslashes($row['info']);
echo <<<my_results
Info: {$row_info}
my_results;

However, I do not recommend that approach. Rather do it like this:

echo 'Info:' . stripslashes($row['info']);

Because {stripslashes($row['info'])} doesn't work indeed and stripslashes({$row['info']}) is an anecdote!

Upvotes: 0

genesis
genesis

Reputation: 50966

$var = stripslashes($row['info']);

is more correct. Or in string, use it like this

echo "something".stripslashes($row['info'])." some more thingy";  

Upvotes: 0

user229044
user229044

Reputation: 239240

stripslashes returns the modified string, leaving its argument unchanged. You have to assign the result to a variable:

$var = stripslashes($row['info']);

That said, why are you doing this? You almost certainly shouldn't be. There is no reason to strip slashes on data coming from the database, unless you've double-escaped the slashes when the data was inserted.

Upvotes: 1

Related Questions