Results 1 to 4 of 4

Thread: php replace letter in string

  1. #1
    Mobility Regular supermobi's Avatar
    Join Date
    Oct 2007
    Posts
    132

    Default php replace letter in string

    I need some help trying to replace a letter from a string.
    I have a mysql database with names of places, in spanish.
    The thing is that the names(985 records) all have the spanish accents without the proper html-escape equivalent, and thus, the mobile browser can't recognize it and writes a ? sign, and it looks horrible.

    So, Im trying to replace each accent with the proper html-escape equivalent (&-#-225; for á, &-#-237; for í, etc...)<-- without the '-'.
    So when I post to the database it posts with those codes instead of the accent.

    I'm making a routine to go over each letter of each name and look for these accents and replace them with the code.
    This routine is supposed to work, but it doesnt work
    Here it is, if you need more info please let me know.
    i'm putting a '-' on the html-escape equivalents to prevent your browser from translating it to the proper character, so you can see the code.

    ************ begin ********
    // $row has all the names
    // some example names are "Café de la Plaza" "El Bodegón de Gaspar"
    // I have to replace the accents for the proper code
    // ex. é = "-&-#233; <-- without the '-'
    while($row = mysql_fetch_row($dbResult))
    {
    echo "$row[0]<br>\n"; //<-- for comparison purposes only

    $original = $row[0]; //<-- $original has the name
    //$original = explode(" ",$row[0]); <-- tried but doesnt work
    $num = strlen($original); //<-- $num has the lenght of the name

    for($y=0;$y<$num;$y++) //<-- $num is the control
    {
    switch ($original[$y]) //<-- goes through all the letters to verify
    {
    case "á":
    $original[$y] = "&-#-225;"; //<--repaces the letter with "&" only
    // so for example "Café" becomes Caf&" , not what i want...
    // also tried the code escapes "&\#225;" and "\á"
    // also tried this other function:
    //substr_replace($original,"é",$y,0); <-- doesnt do anything
    break;

    case "é":
    $original[$y] = "&-#-233;";
    break;

    case "í":
    $original[$y] = "&-#-237;";
    break;

    case "ó":
    $original[$y] = "&-#-243;";
    break;

    case "ú":
    $original[$y] = "&-#-250;";
    break;

    case "ñ":
    $original[$y] = "&-#-241;";
    break;

    case "ü":
    $original[$y] = "&-#-252;";
    break;

    case "Ñ":
    $original[$y] = "&-#-209;";
    break;
    }
    }

    //$original = implode($original); // <-- tried in conjuction with explode() but doesnt work
    echo "$original <br>$num\n<br>\n\n"; // <-- just to check output
    // when i finally get the output right i will replace this for an
    // modify sql statement to modify the database

    }
    ************* end ***************

    Any comments, solutions, ideas are very very welcome.
    Thanks for the help

  2. #2

    Default

    You can use any of the following php functions:

    str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

    string htmlspecialchars ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )

    Check the link below for more info on how to implement:

    http://us2.php.net/htmlspecialchars
    dir.mobi--> The dotmobi directory. List your .mobi today.
    Check out more than 1000 developed .mobi sites here: View All
    eindia.mobi -India's Mobile Portal.
    bMarks.mobi - Mobile Social Bookmarks.

  3. #3
    Mobility Regular supermobi's Avatar
    Join Date
    Oct 2007
    Posts
    132

    Default

    Quote Originally Posted by vcool View Post
    You can use any of the following php functions:

    str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

    string htmlspecialchars ( string $string [, int $quote_style [, string $charset [, bool $double_encode ]]] )

    Check the link below for more info on how to implement:

    http://us2.php.net/htmlspecialchars
    The str_replace I've already tried. I'll check out the htmlspecialchars,
    Thanks for the info.

  4. #4
    Not a member
    Join Date
    Jun 2007
    Location
    Asunción
    Posts
    130

    Default

    Hello,

    You don't have to do that, is perfectly ok to display latin characters in a mobile browser. In order for this to work, you have to display your page on UTF8 and make sure your web server is displaying the page also in UTF8.

    The colate of your database must be in UTF8 as well.

    I have done many mobile sites in spanish with acent, and ñ.

    Let me know if you need help.

    Best regards,

Similar Threads

  1. femto- replace bluetooth and wireless?
    By gogo in forum News & Discussion
    Replies: 1
    Last Post: 03-28-2008, 01:30 PM
  2. Look at this threatening letter I got
    By Binaryman in forum News & Discussion
    Replies: 5
    Last Post: 12-24-2007, 09:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
A Yup.mobi Mobile Site
Mobile Dating