Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

quick function to replace ' with ' in php

Having a mental block....

I know this is so easy.... but nothing is going my way today!

Can anyone help me with a quick function to search a string and escape all apostrophes in php. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use:

$changed_string = str_replace("'","\'",$input_string)

You can also make use of the library function addslashes. Remember it will add slashes in front of single quote ('), double quote ("), backslash () and NULL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...