Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   What is the php regular expression to get everything before a certain character? (https://www.warriorforum.com/programming/58324-what-php-regular-expression-get-everything-before-certain-character.html)

zerugaze 20th February 2009 11:20 PM

What is the php regular expression to get everything before a certain character?
 
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.

wayfarer 21st February 2009 09:05 AM

Re: What is the php regular expression to get everything before a certain character?
 
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


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