ucwords/strtolower help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DevTony
Forum Newbie
Posts: 4
Joined: Fri Sep 16, 2005 8:02 pm

ucwords/strtolower help

Post by DevTony »

Hi I have some trouble here is my code below:

Code: Select all

$Title = ucwords(strtolower($row['Title']));
    echo $Title ;
The thing is some of the text has symbols such as ' in the words and when it's echoed it shows up as a ? instead of a ' some help would be nice thanks :D .
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I don't have that problem when I use the same scenario you are using. Perhaps you're using an unrecognized character set?

A pretty impractical way around it would be:

Code: Select all

$title = ucwords(strtolower($row['Title']));
$newtitle = str_replace("?","'",$title);

echo $title;
This would of course replace any valid question marks with ' so it's a little impractical.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
DevTony
Forum Newbie
Posts: 4
Joined: Fri Sep 16, 2005 8:02 pm

Post by DevTony »

That would work but if I ever did want to use a ? it wouldn't but thanks. Anyone one know anyother way without having to replace the ?.
User avatar
jwalsh
Forum Contributor
Posts: 202
Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH

Post by jwalsh »

is it ' or `, probably a character set issue.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

heh. Not that it's the most useful suggestion but you could always check to make sure it's not ? then a space, if it's not a question mark then a space then replace it with a ', otherwise leave it alone. Most people put a space after punctuation so that'd be a work around to your problem though certianly not a fix.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

I dont see wot you are saying does happen.

Code: Select all

<form action = '' method = 'get'>
	<input type = 'text' value = '' name = 'Title' />
	<input type = 'submit' value = 'submit' name = 'sub' />

</form>

<?php

$Title = ucwords(strtolower($_GET['Title'])); 
echo $Title ; 

?>

Code: Select all

dsfdsaf@#$@Q$!#$	Dsfdsaf@#$@q$!#$
sdfsd''''''sdafds	                Sdfsd\'\'\'\'\'\'sdafds
sdfds??????sdfdsaf	                Sdfds??????sdfdsaf
sdfs\\///////		Sdfs\\\\///////
If you can infer from the code, as magic_quotes is on, it automatically escapes ' and \. you can strip it and use mysql_escape_string and if the output of ucwords(strtolower($string)) has escape chars you can again run stripslashes()
Post Reply