Solved

Having problem with php str_replace function

Posted on 2013-05-14
2
352 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 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