Jump to content

ereg() / ucfirst() question


Luodeni

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.