Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 13-03-06
scifind's Avatar
thin[box]king
 
Join Date: Aug 2003
Location: Cambridge
Posts: 1,844
Thanks: 8
Thanked 4 Times in 4 Posts
scifind is an unknown quantity at this point
  Str replace within preg relace

Trying to replace spaces with underscores within a preg replace

I have tried
PHP Code:
$mystring preg_replace("'<i>([a-zA-Z0-9 ]*)</i>'""<a href=\"".str_replace(" ","_",$1).".html\">$1</a>"$mystring); 
and get a parse error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in error.

Any suggestions
__________________
Earn an average of £45 per sale. | New Star Trek Trailer | Looking for Mobile Phone Link Swaps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 13-03-06
drivetowin's Avatar
Driving to win
 
Join Date: Aug 2003
Location: If I'm not at home, I'm in hospital
Posts: 7,363
Thanks: 5
Thanked 8 Times in 5 Posts
drivetowin seems to know their stuff
Have you tried it with single quotes rather than double quotes in the str_replace

i.e. str_replace(' ','_',$1)
__________________
Never argue with idiots. They just drag you down to their level and then beat you with their experience.

If ignorance is bliss then some of the people I know must be orgasmic.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 13-03-06
scifind's Avatar
thin[box]king
 
Join Date: Aug 2003
Location: Cambridge
Posts: 1,844
Thanks: 8
Thanked 4 Times in 4 Posts
scifind is an unknown quantity at this point
Still same errors I am afraid
__________________
Earn an average of £45 per sale. | New Star Trek Trailer | Looking for Mobile Phone Link Swaps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 13-03-06
Swiss's Avatar
memoryfinder.co.uk
 
Join Date: Jun 2005
Location: Wiltshire, UK
Posts: 343
Thanks: 0
Thanked 0 Times in 0 Posts
Swiss is an unknown quantity at this point
Variable names can not have a number as the first character, letters or underscores only.
__________________
Kris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 13-03-06
Registered User
 
Join Date: Mar 2004
Location: Reading, UK
Posts: 301
Thanks: 0
Thanked 0 Times in 0 Posts
dmorison is an unknown quantity at this point
A few issues going on here.

Firstly; in your match expression; you are trying to match against the closing HTML tag </i>. Unfortunately; the forward slash character delimits the match component from modifier codes that can change the behaviour of the regular expression parser. Therefore, it is necessary to escape the forward-slash in the match expression using the back slash.

Secondly; in order for the second parameter to preg_replace to be processed as PHP code, you need to use the "e" modifier in the match expression. A modifier (see previous paragraph) is included in the match expression at the end, preceeded by the forward slash character. Overall, the match expression you need is:

'/<i>([a-zA-Z0-9 ]*)<\/i>/e'

Finally; in order for the second parameter to be processed as PHP code it must be a string value containing PHP, not actual PHP itself... The code must return a string when evaluated; in other words it must start and end with either double or single-quotes. Any other double-or single quotes within the string must be escaped if required. I think the match expression that should work for what you want to do is:

'"<a href=\'".str_replace(" ","_","$1").".html\'>$1</a>"'

Overall, this makes your final code:

PHP Code:
$mystring preg_replace('/<i>([a-zA-Z0-9 ]*)<\/i>/e''"<a href=\'".str_replace(" ","_","$1").".html\'>$1</a>"'$mystring); 
Note that this removes the italic tags. If you want to keep the italics you will need to include them in the replacement string.

Hope that works.....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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
Excel - find & replace problem Wardy Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 4 07-01-06 01:29 PM
PHP and MySQL - Find and Replace - Update Barry Widgets, Coding, AJAX, PHP - Technology & Affiliate Marketing 2 26-04-04 03:16 PM


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

Content Relevant URLs by vBSEO 3.2.0 RC7