We help IT Professionals succeed at work.

Replace tick mark with "star" in PHP

Bill Sullivan
on
Hi Experts, I'm trying to replace a tick mark in a variable with a "star" before sending it to my MySQL table (if I leave the tick mark in, MySQL assumes the field to close).  When I use preg_replace, I get the following error:

Warning: preg_replace() [function.preg-replace]: No ending delimiter ''' found in /Library/WebServer/Documents/TransferRawData.php on line 144

The table does update, but the field that is to be updated with the variable is blank (all other fields update properly).

Here is the PHP command I use to replace the tick mark with a star:

$Misc4Desc = preg_replace("'","*",$Misc4Desc);

Any help will be greatly appreciated!
Comment
Watch Question

$Misc4Desc = preg_replace("/\'/","*",$Misc4Desc);

Commented:
$Misc4Desc =str_replace("'","*",$Misc4Desc);
Commented:
Just use addslashes.

$Misc4Desc = addslashes($Misc4Desc);

http://php.net/manual/en/function.addslashes.php

Author

Commented:
Thanks!