Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,821 answers

573 users

How to add backslashes in front of a specified characters in a string with PHP

3 Answers

0 votes
$str = "php c c++ java";

$str = addcslashes($str, 'c');

echo $str;




/*
run:

php \c \c++ java

*/

 



answered Sep 25, 2023 by avibootz
0 votes
$str = "php 9 c 17 c++ 20 java 21";

$str = addcslashes($str, '0..9');

echo $str;




/*
run:

php \9 c \1\7 c++ \2\0 java \2\1

*/

 



answered Sep 25, 2023 by avibootz
0 votes
$str = "php 9 c 17 c++ 20 java 21 ada 2012";

$str = addcslashes($str, 'a..d');

echo $str;




/*
run:

php 9 \c 17 \c++ 20 j\av\a 21 \a\d\a 2012

*/

 



answered Sep 25, 2023 by avibootz
...