문제

Which function processes a string putting a backslash before every apostrophes? In other words, I want that

$string="L'isola";
echo somefunction($string);

returns:

L\'isola
도움이 되었습니까?

해결책

You have to use addslashes() method to escape the quote Ex:

<?php
$str = "Is your name O'reilly?";

// Outputs: Is your name O\'reilly?
echo addslashes($str);
?> 

and the reverse method is stripslashes() which remove slashes Ex:

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

다른 팁

you can use the addslashes() function more information can be found here

str_replace will do that for you.

str_replace("'", "\'", $mystring);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top