Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Generating backslash in a string in PHP

I have the following string that the ultimate goal is to use it in like sql. The output should be '%"cardSelected":"120-B-110-C"%' .

But the output of this string is generating with backslashes like this below '%\"cardSelected\":\"120-B-110-C\"%'

$search_term = '"cardSelected":"120-B-110-C"';
$like =  '%'. $search_term .'%';
        
$sql = $wpdb->prepare(
       "SELECT * FROM $wpdb->posts WHERE post_status = %s AND post_content LIKE %s;",
       'publish',
       $like,
);

I tried using str_replace as below, but the slashes were not removed either

$search_term = '"cardSelected":"120-B-110-C"';
$like =  str_replace('\\','','%'. $search_term .'%');
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!