![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Is there a PHP function that only adds slashes to double quotes NOT single quotes
The json_encode function can be used to add slashes to double quotes. Also ‘addcslahses’ can also be used to add ‘\’ to specific characters −
Example
<?php $str = addcslashes("Hello there!","t"); echo($str); ?>
Output
This will produce the following output −
Hello \there!
The ‘addcslashes’ function is used to return a string with backslashes in front of the specific characters. It is a case sensitive function and should usually not be used with 0 (null), r (carriage return), n (newline), f (form read), t (tab), v (vertical tab) values. This is because values like \0, \r,
, \t, \f and \v are pre-define escape sequences.
In the above code, the ‘addcslashes’ function is called on the string by specifying that the backslash has to occur before the character ‘t’.
Advertisements