Jump to content

Recommended Posts

hey everyone,

 

Earlier today I was doing some PHP programmign for a web application I m making and I got a very unpleasent error. My application is UTF-8 and that works fine. But when I was updating a record which uses chinese characters for example it just made a weird character. thsi was caused because I used

 

<?php

    $companyStreetName = mysql_real_escape_string( ucfirst( $_POST['companystreetname'] ) );

?>

 

Now I found out the error was caused by the ucfirst() so I rewrote my code to this:

 

<?php

$companyName = mysql_real_escape_string( $_POST['companyname'] );

if ( ereg('[a-z]', $companyName) )

$comapnyName = ucfirst( $companyName );

}

else

{

$companyName;

}

?>

 

however It doesn't work for some reason, does anyone know why not? i d be very happy if someone could help me with this :)

Link to comment
https://forums.phpfreaks.com/topic/147395-ereg-ucfirst-question/
Share on other sites

well the only thing I can see wrong with this is different character encoding, has different positions for the character

 

for example, 32 would be the charCode for UTF-8 for a space, and 160 would be a non-breaking space in UTF-8, meanwhile in chinese they may have characters like this, like a b c, but I am not 100% positive, but I'd assume they'd be at different positions on that encoding.. and when everything boils down to it, everything is broken down to the asc value of the character in question

 

although I'm not completely positive about any of the above, thats just about what I figure how happens, which would explain the ucfirst() failure and ereg failure to match the letters

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.