Jump to content

remove unwanted &

- - - - -

  • Please log in to reply
4 replies to this topic

#1
shivam

shivam

    Newbie

  • Members
  • PipPip
  • 27 posts
i have an array of URLs, but these URL contains the unwanted string "&" so many times..

How can i remove & from the strings of that array ???

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
There are a few ways, probably the most simple is this:
$cleanArray = array();
foreach($strings as $string) {
  $cleanArray[] = str_replace("&", "&", $string);
}
You can use urldecode as well although that will replace all %foo or &bar with their respective symbols.

Edited by Alexander, 12 March 2011 - 10:56 PM.
Typographical error

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
shivam

shivam

    Newbie

  • Members
  • PipPip
  • 27 posts
There is some problem with this function..
if i am using & for replacing & nothing changes & if i use something else like "abc" instead of & for replacing & it works..
it means whenever & is in the link the amp; also comes automatically..:c-mad:

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
I am not sure what you are referring to, take this working example:
Ideone.com | Online PHP Interpreter & Debugging Tool

It resolves the encoded & successfully. Is that what you meant?
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
shivam

shivam

    Newbie

  • Members
  • PipPip
  • 27 posts
hey thanx i am using var_dump instead of print_r:c-biggrin:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users