-1

Possible Duplicate:
how to replace special characters with the ones they’re based on in PHP?

Here is sample code:

$code="CSC113α";//other codes PHY123β,MAT324δ

    ////return last character of the code
    $lastchar=substr($code, -1);

    // returns rest code without last character..
    $rest = substr($code, 0, -1);  

    //Make standard course_ID with a,ß..
    switch ($lastchar)
    {
    case 'α':{
      $lastchar='A';
      $id=$rest.$lastchar ;
      $full_course_id=$id;
      break;
    }
    case 'β':{
      $lastchar='B';
      $id=$rest.$lastchar ;
      $full_course_id=$id;
      break;
    }
    case 'δ':{
      $lastchar='D';
      $id=$rest.$lastchar ;
      $full_course_id=$id;
      break;
    }
    default:
      $full_course_id=$code;
    }

Here I try to replace α,β,δ with A,B,D...This code is not working..Here variable code values comes from another script with special characters..Here I want to replace those characters with normal characters.. I want get final out put like 'CSC113A'..but this switch code doesn't work for me...please help me to do this...thxx in advanced....

Community
  • 1
  • 1
Dong Li
  • 29
  • 5

1 Answers1

1

Why not simply use the function str_replace? I've done a test and it works for me!

<?php
$code="CSC113α";
$full_course_id = str_replace(array('α','β', 'δ'), array('A', 'B', 'D'), $code);
m4t1t0
  • 5,669
  • 3
  • 22
  • 30
  • yes frnd ..this code is working perfectly...thanxx so much....u all are doing great help for the upcoming coders,.... – Dong Li Dec 14 '12 at 13:39