PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I escape a string with slashes?


This is really easy to do, and simply relies on you using the addslashes function like this:

<?php
$contents 
"I'm very happy today";
echo 
addslashes($contents);
//I\'m very happy today
?>


That's all there is to it, simply done. Remember that if you want to take those slashes off, for instance once data has been extracted from a database, you can use the opposite function called stripslashes to remove them.



Comment on this Question and Answer >>>

ASK A QUESTION

More strings PHP Questions

How do I convert relevant characters in a string to HTML entities?

How do I make the first letter of each word upper case?

How do I remove trailing whitespace from a string?

I retrieve data from a Mysql database and insert it into a textfield form. The data that I retrieve have a / at the end of the string. The data in the database does not have this / in the data. How do I remove this /?

How do I format the output of a string?



Custom Search