Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 20th Feb 2009, 11:20 PM   #1
Warrior Member
 
Join Date: 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default
What is the php regular expression to get everything before a certain character?
Share on: 
fb share twitter share gplus share more share

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  
Unread 21st Feb 2009, 09:05 AM   #2
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: What is the php regular expression to get everything before a certain character?
Share on: 
fb share twitter share gplus share more share

Using a regular expression here is not what you need. Instead, you should explode the string using the ":" as the delimiter. The explode() function splits up strings into an array, using whatever symbol you like to break it.
PHP Code:
$ string = "table:column";
$ array = 
explode(":", $ string);
//now, $ array  is ([0] => "table", [1] => "column") 
I had to place a space between the $ and the variable name, because for some reason the forum was removing them

I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
wayfarer is offline  
Closed Thread


Bookmarks

Tags
character, expression, php, regular


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




All times are GMT -6. The time now is 09:59 AM.