Cut text out from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ejasonwu
    New Member
    • Nov 2008
    • 2

    #1

    Cut text out from a string

    I have a string : 420_million_peo ple-(Softeware_Comp uter)/en

    i want to have string cut like

    string1 before -
    string1 : 420_million_peo ple

    and

    string2 before between ()
    string2: Softeware_Compu ter

    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

    Code:
    $query = "SELECT tmw_page.page_title FROM tmw_page";
    $qry_result = mysql_query($query) or die(mysql_error());
    $result=mysql_query($query);
    	while($row = mysql_fetch_row($result))
    	{
    
    		foreach($row as $values)
    		{
    
    		
    			preg_match('/.*-/i', $values, $result);
    			echo ($result[0]);
    			echo("<br><br>$values2<br>");
    
    			
    			list($junk, $good) = split('(', $string);
    			list($good, $junk) = split(')', $good);
    			echo $values;
    
    		}
    	}
    Last edited by Markus; Nov 2 '08, 11:01 AM. Reason: added # tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    • ejasonwu
      New Member
      • Nov 2008
      • 2

      #3
      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

      Comment

      Working...