Solved

Having problem with php str_replace function

Posted on 2013-05-14
2
356 Views
Last Modified: 2013-05-14
Hi
I'm have a issue with the php function str_replace.

I have the following block of text from with I want the function to find
s:26 "Simple Design with 1 Image" and replace it with s:19 "Design with 1 Image"

a:1:{s:1:"a";a:1:{i:1;a:3:{s:2:"id";s:1:"1";s:4:"name";s:8:"Artwork?";s:7:"options";a:4:{i:0;a:2:{s:2:"id";s:1:"1";s:4:"name";s:22:"Supplying Own [¿0]ash";}i:1;a:2:{s:2:"id";s:1:"2";s:4:"name";s:34:"Text Only with Simple Fonts a[¿1]";}i:2;a:2:{s:2:"id";s:1:"3";s:4:"name";s:26:"Simple Design with 1 Image";}i:3;a:2:{s:2:"id";s:1:"4";s:4:"name";s:35:"Complex Design with Multiple Images";}}}}}

the functions work if I just replace Simple Design with 1 Image but when I have the whole string with double quotes it doesn't work.

This is the code i'm using and $row[0] is the above block of text that is pulled from the database
$strfind1 = "s:26 \"Simple Design with 1 Image\"";
$strrep = "s:19 \"Design with 1 Image\"";

$newdata = str_replace($strfind1, $strrep, $row[0]);

Open in new window


Thank you in advance for any help
0
Comment
Question by:ACEAFTY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39164047
looking at the text being searched ($row[0]) i can see that there's : between s:26 and the text Simpla Desing, while you are looking for a space between them.
so basically this is what you should replace:
s:26:"Simple Design with 1 Image"
and not
s:26 "Simple Design with 1 Image"

so try this instead:
$strfind1 = "s:26:\"Simple Design with 1 Image\"";
$strrep = "s:19:\"Design with 1 Image\"";

$newdata = str_replace($strfind1, $strrep, $row[0]);

Open in new window

0
 
LVL 1

Author Closing Comment

by:ACEAFTY
ID: 39164066
Thank you.
Such an obvious mistake, can't believe I missed it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question