/    Sign up×
Community /Pin to ProfileBookmark

Can you preg_replace unserialized string?

Was wondering if you can preg_replace an unserialized string. My website serialized user input forms and I need to unserialize them. That’s no problem, but I need to replace part of the unserialized string. For example….unserializing may come out as this in a loop.

First Name: John
Last Name: Doe
E-mail: [email][email protected][/email]
Telephone Number: 123-456-7890

If I needed to have the Telephone Number just come out as 123-456-7890, how would I remove the “Telephone Number: ” part of the string? Is it possible?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 24.2010 — It's not real clear to me what you actually want to change: is all that text in one string, or is it unserialized into an array or an object, or what? In any case, str_replace (or str_ireplace for case-insensitive matching) is probably all you need if there is nothing variable about the text you want to replace:
[code=php]
$text = str_replace('Telephone Number: ', '', $text);
[/code]
Copy linkTweet thisAlerts:
@smohauthorNov 24.2010 — Thanks for your reply. The str_replace didn't work, but it turns out that I'm an idiot because I was echoing the variable $label which happened to show the 'Telephone Number'.

Thanks once again Nogdog
×

Success!

Help @smoh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...