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
What is the php regular expression to get everything before a certain character?
Old 03-01-2009, 07:38 AM What is the php regular expression to get everything before a certain character?
Banned

Posts: 3
Name: zeruga
Trades: 0
For instance, I have the following string:

table:column

I need to get "table" as the result of the php regular expression.

So, I need everything before the ":" symbol

After that regular expression is performed, I would also like to get everything after the ":" symbol, or "column" as well.
zerugaze is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-01-2009, 08:01 AM Re: What is the php regular expression to get everything before a certain character?
Defies a Status

Posts: 1,606
Trades: 0
I think there is more than one way to it. Explode will do the job.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
colbyt is offline
Reply With Quote
View Public Profile
 
Old 03-01-2009, 03:10 PM Re: What is the php regular expression to get everything before a certain character?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Indeed, explode fits perfectly in this situation.
And if you have many table:column pairs, you could for example do this

PHP Code:
$string "table:column;table:column;table:column;table:column";
$pairs explode(';'$string);
$split = array();
foreach (
$pairs as $pair) {
   
$tmp explode(':'$pair);
   
$split[$tmp[0]] = $tmp[1];
}

/* Now $split is an array as in
 * 
 * array(
 *    table => column,
 *    table => column,
 *    etc...
 * );
 */ 
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to What is the php regular expression to get everything before a certain character?
 

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.45548 seconds with 12 queries