Brian Miller 1,638 Posted September 29 Using PHP, how would I convert the following: I "love" Newoin to the following? I “love” Newoin Do you see the use of smart quotes? I can do this in JS but I need to do this in PHP. In JS, I'd do something like... $text = 'I "love" Newoin'; console.log($text.replace(/'/g, "’").replace(/\`/g, "’").replace(/\b"/g, "”").replace(/\"/g, "“")); But I have no idea how to do this in PHP. Please help. Thanks. Share this post Link to post Share on other sites
1 Neil709 1 Posted September 29 Opps, I missed one of the quote types $text = preg_replace(array('/\b"/','/"/',"/'/","/`/"), array('”','“',"’","’"), $text); 1 Share this post Link to post Share on other sites
0 Brian Miller 1,638 Posted September 29 "That's a 'magic' sock." = Incorrect“That’s a ‘magic’ sock.” = Correct Share this post Link to post Share on other sites
0 Neil709 1 Posted September 29 Hey, try the following code, that should work for you. $text = preg_replace(array('/\b"/','/"/',"/'/"), array('”','“',"’"), $text); Share this post Link to post Share on other sites
0 Brian Miller 1,638 Posted September 29 THANK YOU! Share this post Link to post Share on other sites
Using PHP, how would I convert the following:
to the following?
I “love” Newoin
Do you see the use of smart quotes?
I can do this in JS but I need to do this in PHP. In JS, I'd do something like...
$text = 'I "love" Newoin'; console.log($text.replace(/'/g, "’").replace(/\`/g, "’").replace(/\b"/g, "”").replace(/\"/g, "“"));
But I have no idea how to do this in PHP. Please help. Thanks.
Share this post
Link to post
Share on other sites