Affiliate Marketing
Forum Search


Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 15-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
  preg_split or not preg_split, that is the question!

Morning All,

Yet another topic on the keyword tracking topic. I have a string of words e.g.

"holiday villa in", essex, "united kingdom"

I need to split the string into an array so that the quoted words stay together e.g.

Array 0 => Holiday villa in
1 => essex
2 => United Kingdom

Any ideas? I thought about using preg_split but wonder if there is a better tool?

Cheers,

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 15-08-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
If it's not too long a list, I would just do an explode() followed by trim() supplying the quote character as an optional character to trim; for example:

PHP Code:
<?php
  $keyword_list 
'"holiday villa in",essex,"united kingdom"';
  
$keyword_array explode(",",$keyword_list);
  foreach(
$keyword_array as $k => $v$keyword_array[$k] = trim($v,'"');
  
print_r($keyword_array);
?>
gives...

Code:
Array ( [0] => holiday villa in [1] => essex [2] => united kingdom )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 15-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
Sounds good, potentially I could have a lot of keywords but that does the trick for now.

Many Thanks,

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
  #4 (permalink)  
Old 15-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
You may need to watch out if you have any commas inside you quoted strings, e.g.
PHP Code:
$keyword_list '"holiday, villa",essex,"united kingdom"'
would list holiday and villa separately.

There is quite a bit of discussion about that problem in the comments to the explode manual page.

If you won't have commas inside the quoted strings then
PHP Code:
$keyword_list '"holiday villa in",essex,"united kingdom"';
$keyword_array explode(",",str_replace('"','',$keyword_list));
print_r($keyword_array); 
will probably be a bit quicker.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 15-08-06
esnagel's Avatar
Registered User
 
Join Date: Apr 2005
Location: Buffalo, NY USA
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
esnagel is an unknown quantity at this point
Look at http://us2.php.net/fgetcsv - sounds like it's exactly what you're looking for. Handles the , inside "", too
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 17-08-06
Technophobe Geek
 
Join Date: Jan 2005
Location: Cumbria, UK
Posts: 482
Thanks: 0
Thanked 1 Time in 1 Post
trevHCS is an unknown quantity at this point
One other possible is preg_match_all() which might work if the CSV processor doesn't work (incase it doesn't like the lack of quotes on "essex".

Trev
__________________
UK Hotel :: UK Cottage :: UK Attraction :: Mad Theories
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 17-08-06
Marc Gear's Avatar
Registered User
 
Join Date: Aug 2003
Posts: 572
Thanks: 0
Thanked 0 Times in 0 Posts
Marc Gear is an unknown quantity at this point
This is just why you should use XML
__________________
<b>Marc Gear
Senior Developer
Webgains Ltd.
<a href="mailto:marc@webgains.com">marc@webgains.com</a></b>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 17-08-06
Technophobe Geek
 
Join Date: Jan 2005
Location: Cumbria, UK
Posts: 482
Thanks: 0
Thanked 1 Time in 1 Post
trevHCS is an unknown quantity at this point
Is that XML with or without attributes in every tag, DTD's and all the rest of the strange stuff that sometimes goes with it?

Trev
__________________
UK Hotel :: UK Cottage :: UK Attraction :: Mad Theories
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 17-08-06
Marc Gear's Avatar
Registered User
 
Join Date: Aug 2003
Posts: 572
Thanks: 0
Thanked 0 Times in 0 Posts
Marc Gear is an unknown quantity at this point
Quote:
Originally Posted by trevHCS
Is that XML with or without attributes in every tag, DTD's and all the rest of the strange stuff that sometimes goes with it?

Trev
XML with attributes, schemas, namespaces and all sorts of crazy stuff.

If only people used the right tools no one would ever complain about XML
__________________
<b>Marc Gear
Senior Developer
Webgains Ltd.
<a href="mailto:marc@webgains.com">marc@webgains.com</a></b>
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
Question about Adsense Paulus The Affiliate Marketing Lounge 7 13-02-06 02:53 PM
ok may be a dumb question regardinf affiliate managers justhomdotcom The Affiliate Marketing Lounge 8 06-12-05 12:59 PM
Merchant question: more than 1 network justhomdotcom The Affiliate Marketing Lounge 7 03-08-05 05:15 PM