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

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

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

Disclosure: My content contains affiliate links.

43,181 questions

56,073 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
...