Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 12-08-06
Northern Monkey's Avatar
Member
 
Join Date: Jan 2004
Location: UK
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Northern Monkey is an unknown quantity at this point
  PHP - String replacement

I have the following code:

echo $ref_url.'<br>';
echo $keywords[1];

if (isset($keywords[1]) and ($keywords[1]!="") and ($keywords[1]!=" "))
{
$keywords1=preg_replace("/+/"," ",$keywords[1]);
}

echo $keywords;

Which produces the following:

http://localhost/hvi/viewvilla.php?h...lla+rome&meta=
holiday+villa+rome
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in c:\program files\apache group\apache\htdocs\hvi\logger.inc on line 91

After - holiday+villa+rome

Any idea why my +'s aren't changing to spaces??

NM.
__________________
Holiday Villa In<br>
<font size=2>If it moves, kick it. If it doesn't move, kick it till it moves and hen kick it because it moved</font>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-08-06
limboInternet's Avatar
straight talker
 
Join Date: Aug 2006
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
limboInternet is an unknown quantity at this point
try changing the plusses to %20 thats code for space in url strings
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-08-06
Super Moderator
 
Join Date: Aug 2003
Posts: 2,451
Thanks: 0
Thanked 0 Times in 0 Posts
Rich is an unknown quantity at this point
A + is a special character in regular expressions. You should escape it with a \, like: -
$keywords1=preg_replace("/\+/"," ",$keywords[1]);

or, more efficiently, avoid the regular expression and use str_replace: -
$keywords1=preg_replace('+',' ',$keywords[1]);

or, assuming you might end up with other encoded characters in your query, you could use: -
$keywords1=urldecode($keywords[1]);

By the way, it's also more efficient to use single quotes rather than double quotes if you don't need to substitute variables inside the string, though it is minute differences.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 13-08-06
Northern Monkey's Avatar
Member
 
Join Date: Jan 2004
Location: UK
Posts: 142
Thanks: 0
Thanked 0 Times in 0 Posts
Northern Monkey is an unknown quantity at this point
Thanks for all the comments, worked a treat!

NM.

P.S. I also use single quote normally where possible but they always creep in places
__________________
Holiday Villa In<br>
<font size=2>If it moves, kick it. If it doesn't move, kick it till it moves and hen kick it because it moved</font>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP String Function Remove Last X Chr of String scifind Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 3 08-07-05 08:42 AM
Anyone anygood with xml, php, mysql and Affiliate Window AnnonnyMouse The Affiliate Marketing Lounge 1 23-09-04 11:00 AM
php: find string length morleymouse Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 2 25-06-04 11:47 AM
how to shorten a string (php) morleymouse Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 3 27-03-04 05:35 PM
Removing forward slashes / from a string in PHP giveasyouget Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 6 19-09-03 11:06 PM


Affiliate Marketing RSS Feeds - Contact Us - Affiliate Marketing - Archive - Privacy Statement - Top

Content Relevant URLs by vBSEO 3.2.0 RC7