/    Sign up×
Community /Pin to ProfileBookmark

PHP Variable String Help

I’m looking for some help with converting special characters within a string to a different character.

Current Code:

[code]<?php echo $use[‘value’] ?>[/code]

$use is an array
[‘value’] is the string within the array

I’m taking the data from $use[‘value’] and using it in a URL. The problem is if $use[‘value’] is something like “Home Projects & Hobbies” the URL gets messed up; it will look like /Home%20Projects%20&%20Hobbies.

So, if possible, I want to write a little script that will take the spaces of the string and convert them into “-” and take the “&” symbol and convert it into “and”.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 28.2011 — Try the [url=http://php.net/str_replace]str_replace[/url]() function.
Copy linkTweet thisAlerts:
@VinceMalauthorFeb 28.2011 — Thanks that worked
Copy linkTweet thisAlerts:
@Matt_DMar 03.2011 — You might be interested in some of the builtin functionality PHP has to offer to handle data being passed to & from forms.

[B]htmlspecialchars_decode[/B] (http://fr.php.net/manual/en/function.htmlspecialchars-decode.php) coverts your html safe content back to plain text, to answer your question.

And then there is [B]htmlspecialchars[/B](http://fr.php.net/manual/en/function.htmlspecialchars.php) which converts plain text to HTML safe content.



hope this helps
×

Success!

Help @VinceMal 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 4.27,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...