Solved

Having problem with php str_replace function

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now