Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Regex, need help ASAP
Old 05-06-2005, 07:12 AM Regex, need help ASAP
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
i need to know this fairly quickly so if anyone could help me i would very very appreciative

ok i have this string in php

Code:
START
New York
END
START
London
END
START
Sydney
END
START
Tokyo
END
i need a short php script that involves regex that goes through that string and returns an array something similar to

PHP Code:
[0] => "New York"
[1] => "London"
[2] => "Sydney"
[3] => "Tokyo" 
i will be very thankful to whoever can help me out
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
 
Register now for full access!
Old 05-06-2005, 07:23 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
<?

$string 
"START
New York
END
START
London
END
START
Sydney
END
START
Tokyo
END"
;

$re "!START\r?\n?(.*?)\r?\n?END!";
preg_match_all($re$string$match);
$cities $match[1];

?>
Goes?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-06-2005, 07:27 AM
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
thankyou, ill begin testing soon
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
Old 05-06-2005, 07:50 AM is this possible too?
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
is this possible too?

have this string
Code:
START (CITY1)
New York
END
START (BLABLA)
London
END
START (CITY3)
Sydney
END
START (GOOGLEROX)
Tokyo
END
and it return this??::!::



PHP Code:
["CITY1"] => "New York"
["BLABLA"] => "London"
["CITY3"] => "Sydney"
["GOOGLEROX"] => "Tokyo" 
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
Old 05-06-2005, 07:59 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
It should work, because I run it before posting and it worked fine. But depending on what is your OS you may replace \r?\n? to simply \n (on Unix-like) or \r on Mac or \r\n on Windoze.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-06-2005, 08:01 AM
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
i dont have a problem with the original post

but i just want too see whether or not the second post is also possible... the one with Strings for keys in the array
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
Old 05-06-2005, 08:35 AM
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Done again
PHP Code:
<?
$string
="START (CITY1)
New York
END
START (BLABLA)
London
END
START (CITY3)
Sydney
END
START (GOOGLEROX)
Tokyo
END"
;

$re "!START \(([^\)]+)\)\r?\n?(.*?)\r?\n?END!";
preg_match_all($re$string$matchPREG_SET_ORDER);

foreach (
$match as $m) {
    
$arr[$m[1]] = $m[2];
}

print_r($arr);
?>
Output:
C:\www\swdl>php zzz.php
Array
(
[CITY1] => New York
[BLABLA] => London
[CITY3] => Sydney
[GOOGLEROX] => Tokyo
)

What is it all for?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 05-06-2005, 08:39 AM
pr0jekt's Avatar
Skilled Talker

Posts: 60
Location: Victor Harbor, South Australia
Trades: 0
ive made the sample city string fairly easy to understand so i dont have to explain what im doing but i am making the skin portion of a forum system i am contructing. The forum will be very powerful in the end and i just needed to get over this tiny hurdle. many thanks to you mtishetsky

i am always welcoming people to help develop this so if u are interested then well just shout
__________________

Please login or register to view this content. Registration is FREE


Im new here so play nice :)
pr0jekt is offline
Reply With Quote
View Public Profile Visit pr0jekt's homepage!
 
Reply     « Reply to Regex, need help ASAP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.53640 seconds with 12 queries