PHP String Function, How can I isolate what is in the last set of parens? -


i have write string function takes whatever in last parens , put new variable, without parens. in case, ups next day air.

$oldvar = 'united parcel service (1 pkg x 4.00 lbs total) (ups next day air)'; $newvar = 'ups next day air'; 

thanks!,

the following code sets $newvar correct string if there matching parens in $oldvar , false otherwise.

$oldvar = 'united parcel service (1 pkg x 4.00 lbs total) (ups next day air)'; $poslastopeningparenthesis = strrpos($oldvar, '('); if ($poslastopeningparenthesis === false) {     $newvar = false; } else {     $poslastopeningparenthesis++; // move position behind opening parenthesis     $poslastclosingparenthesis = strpos($oldvar, ')', $poslastopeningparenthesis);     if ($poslastclosingparenthesis === false) {         $newvar = false;     }     else {         $newvar = substr($oldvar, $poslastopeningparenthesis, $poslastclosingparenthesis - $poslastopeningparenthesis);     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -