Link to home
Start Free TrialLog in
Avatar of Richard Coffre
Richard CoffreFlag for France

asked on

String manipulation (reverse and delete)

Hi,

I want to transform string.
For example when I have this : "VOITURE (LA)" I want to obtain "LA-VOITURE".
So the steps are :
1. set the article at the beginning
2. delete the parenthesis
3. replace the space by a hyphen.

TIA
Avatar of shivsa
shivsa
Flag of United States of America image

$str = '"VOITURE (LA)" ';
$first= 0;
$last = 0;
for ($i = 0; $i < strlen($str); $i++) {
  if($str[$i] == '(' ) {
     $first = $i ;
  if ($str[$i] == ')') {
     $last = $i ;
  }
}
$i=0;
for ($j=$first+1 ; $j < $last; $j++) {
  $rep[$i++] =  $str[$j];
}
$rep[$i+1] = '"-"';
for ($k=0; $k < $first ; $k++){
  $rep[$i++] = $str[$k];
}
     
ASKER CERTIFIED SOLUTION
Avatar of Giovanni G
Giovanni G
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial