General / Allgemeines > Programming

working with string patterns...

<< < (2/2)

Rembrandt:
my second example in my first post works now, i forgot:
[0]

so here is version as "function":

function special_rtrim($string){
  preg_match_all('#\([^\)]*\)#', $string, $matches);
  $last_match = array_pop($matches[0]);
  $string = preg_replace('#\('.$last_match.'\)#' ,"",$string);
return $string;
}

//$string="This is my data (want to keep this data) (want to delete this data and brackets)";
$string="this is another test #3 (2012) (september) (get rid of me data)";  //needs to become "this is another test #3 (2012) (september)"
//$string="this is test#1 (2012) (delete this data)"; //needs to become "this is test#1 (2012)"
//$string="this is some data test#2 (data to delete)"; //needs to become "this is some data test#2" 

$string = special_rtrim($string);
 
echo $string;


mfg Andi

budduke:
That did it!  :D

Someday I will have to sit down and understand those patterns better. I think that is holding me back in allot of ways...

Thank you Rembrandt for your help!

schmekl:
Thank you andy.

________________________
Software University
Übersetzung Englisch Deutsch

mizeweb:

--- Quote from: Rembrandt on August 19, 2012, 09:10:19 PM ---my second example in my first post works now, i forgot:
[0]

so here is version as "function":

function special_rtrim($string){
  preg_match_all('#\([^\)]*\)#', $string, $matches);
  $last_match = array_pop($matches[0]);
  $string = preg_replace('#\('.$last_match.'\)#' ,"",$string);
return $string;
}

//$string="This is my data (want to keep this data) (want to delete this data and brackets)";
$string="this is another test #3 (2012) (september) (get rid of me data)";  //needs to become "this is another test #3 (2012) (september)"
//$string="this is test#1 (2012) (delete this data)"; //needs to become "this is test#1 (2012)"
//$string="this is some data test#2 (data to delete)"; //needs to become "this is some data test#2" 

$string = special_rtrim($string);
 
echo $string;


mfg Andi

--- End quote ---

thats so good thanks

Navigation

[0] Message Index

[*] Previous page

Go to full version