|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Escaping a plus sign (+)
How does one escape a plus sign in PHP, or rather get it to work in the following script:
PHP Code:
)I'm trying to capture an URL which includes plus signs: http:// www.URL . com/file.php?dog+cat+mouse I'm stripping out the dog+cat+mouse and then stripping the plus signs, replacing them with spaces. Last edited by donatello; 11-21-2009 at 07:26 PM. Reason: English :] |
|
#2
|
||||
|
||||
|
You could use urldecode() on the string (it should take care of the "+" and any "%xx" characters), then apply any other changes you need to the result.
__________________
"That's what the gods are! An answer that will do! Because there's food to be caught and babies to be born and life to be lived and so there is not time for big, complicated, and worrying answers! Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." -- from Nation, by Terry Pratchett freelancer.internet.com Email me |
|
#3
|
||||
|
||||
|
Quote:
It works like a charm: PHP Code:
|
|
#4
|
||||
|
||||
|
You should really be using the str_replace function instead, as it seems you don't need a regular expression to do the match.
PHP Code:
|
|
#5
|
||||
|
||||
|
[resolved]
Quote:
Maybe one of these days I'll know what I'm doing in PHP... ![]() Can anyone explain why? I'm curious to know... is preg_replace more taxing on Apache? is preg_replace being deprecated? or is it just good programming? Thanks! |
|
#6
|
|||
|
|||
|
str_replace has less overhead and is less taxing on the processor especially when you are just replacing a single character. More complicated replaces/searches can justify the extra overhead of the ereg/preg functions.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|