Connecting Tech Pros Worldwide Help | Site Map

Cut text out from a string

Newbie
 
Join Date: Nov 2008
Posts: 2
#1: Nov 2 '08
I have a string : 420_million_people-(Softeware_Computer)/en

i want to have string cut like

string1 before -
string1 : 420_million_people

and

string2 before between ()
string2: Softeware_Computer

string3 after /
string3: en

please help me

below is the code i have try to use (Not working lol)

the string is come from a sql

Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT tmw_page.page_title FROM tmw_page";
  2. $qry_result = mysql_query($query) or die(mysql_error());
  3. $result=mysql_query($query);
  4.     while($row = mysql_fetch_row($result))
  5.     {
  6.  
  7.         foreach($row as $values)
  8.         {
  9.  
  10.  
  11.             preg_match('/.*-/i', $values, $result);
  12.             echo ($result[0]);
  13.             echo("<br><br>$values2<br>");
  14.  
  15.  
  16.             list($junk, $good) = split('(', $string);
  17.             list($good, $junk) = split(')', $good);
  18.             echo $values;
  19.  
  20.         }
  21.     }
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,745
#2: Nov 2 '08

re: Cut text out from a string


Hi.

That regular expression isn't even close.
Check out the tutorial here to see how to use regular expressions.

This could be done by simply using the explode function.
Firstly, you would want to split the string using the "-" char.
Then, split the second part of that with the "/" char.
And finally, trim the ( and ) from the middle part.
Newbie
 
Join Date: Nov 2008
Posts: 2
#3: Nov 3 '08

re: Cut text out from a string


Quote:

Originally Posted by Atli

Hi.

That regular expression isn't even close.
Check out the tutorial here to see how to use regular expressions.

This could be done by simply using the explode function.
Firstly, you would want to split the string using the "-" char.
Then, split the second part of that with the "/" char.
And finally, trim the ( and ) from the middle part.


Thank You for help
it work now
Thanks a lot
Reply