Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2003, 07:19 AM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to starsol
Default str_replace for quotation mark

$before = array("&");
$after = array("&");
$text = str_replace($before, $after, $text);

The above code will replace an occurance of an ampersand in a string with it's HTML equivalent. How can this be done for a quotation mark (") ? I have tried backslashing it, but that gave me parse errors.

Anyone know?

Cheers,
Rupe

Rupe Parnell
www.starsol.co.uk
__________________
Rupe Parnell
www.starsol.co.uk
 
Old August 21st, 2003, 08:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use it's chr ASCI code: str_replace(chr(34), """, $text);

Dan
 
Old August 21st, 2003, 08:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Unreal... The forum kept deleting my "&" from "#34;"
                                              ^^^^
Ak! Make that "ampersand-hash-thrityfour-semicolon"!

Bloody ASP...
 
Old August 21st, 2003, 09:30 AM
Authorized User
 
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to starsol
Default

Thanks Daniel .

Rupe Parnell
www.starsol.co.uk
 
Old August 21st, 2003, 11:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Regular expression strings are tricky at best sometimes, especially when dealing with characters that need to be escaped.

You might also try using a single-quoted string to avoid the first round of variable substitution and escaped character conversion.

'\"' is parsed literally as two characters, where as
"\"" is parsed as just the one. You need the two-character version for your regular expression, I think.


However, this all begs the question, why not just use htmlentities() or htmlspecialchars()?
  http://www.php.net/htmlentities
  http://www.php.net/htmlspecialchars





Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem unclosed quotation mark. HelpHelp waiwaisan VB Databases Basics 1 January 4th, 2007 05:29 AM
Quotation NEO1976 XML 5 July 19th, 2006 10:00 AM
display quotation mark in ASP angelran Classic ASP Basics 2 October 31st, 2005 08:03 AM
please help to develop this quotation prog mjuliao Access 18 August 29th, 2005 10:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.