Solved

Having problem with php str_replace function

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now