|
|
|
||||
|
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() |
|
|||||||
| Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
|
Thread Tools |
|
|
#1 |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Revising text file from ALL CAPS to First Letter Caps.. php script?
Another PHP question. I have a list of 10,000+ phrases line by line in a text file. I need to change it from:
THE BOY JOHNS BIRD FRED SUCKS EAT ME etc etc to: The Boy Johns Bird Fred Sucks Eat Me etc etc Anyone know a php code or easy program/way to do this? |
|
|
|
|
|
#2 |
|
Confirmed User
Join Date: Nov 2007
Location: Kalamazoo, MI
Posts: 2,490
|
$file = str_replace("A","a","$file");
$file = str_replace("B","b","$file"); go all the way to Z... thats really the easiest way that I can think of... obviously theres others but this is a quick way. I've been up all night coding so can't think of a "cleaner" way to do it...
__________________
-- QUOTE ME IT MAKES ME FEEL SPECIAL -- |
|
|
|
|
|
#3 |
|
Confirmed User
Join Date: Nov 2007
Location: Kalamazoo, MI
Posts: 2,490
|
just noticed that you want to keep the caps after a space... alright, that complicates it a bit more... but str_replace can do that too.... just have a space as part of the syntax
__________________
-- QUOTE ME IT MAKES ME FEEL SPECIAL -- |
|
|
|
|
|
#4 |
|
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
Code:
$db = file("filename.txt");
$i = 0;
while (isset($db[$i])) {
$blah = explode(" ", strtolower(trim($db[$i])));
$j = 0;
while (isset($blah[$j])) {
$t = $blah[$j];
$t[0] = strtoupper($t[0]);
$blah[$j] = $t;
$j++;
}
echo implode(" ", $blah) . "\n";
$i++;
}
|
|
|
|
|
|
#5 |
|
►SouthOfHeaven
Join Date: Jun 2004
Location: PlanetEarth MyBoardRank: GerbilMaster My-Penis-Size: extralarge MyWeapon: Computer
Posts: 28,609
|
Code:
<?php
function custom_ucwords($map, $string) {
$inside_word = TRUE;
for ($index = 0; $index < strlen($string); ++$index) {
$is_chr = isset($map[$string[$index]]);
if (! $inside_word && $is_chr) {
$string[$index] = $map[$string[$index]];
}
$inside_word = $is_chr;
}
return $string;
}
$map = array(
'a' => 'A', 'b' => 'B', 'c' => 'C', 'd' => 'D',
'e' => 'E', 'f' => 'F', 'g' => 'G', 'h' => 'H',
'i' => 'I', 'j' => 'J', 'k' => 'K', 'l' => 'L',
'm' => 'M', 'n' => 'N', 'o' => 'O', 'p' => 'P',
'q' => 'Q', 'r' => 'R', 's' => 'S', 't' => 'T',
'u' => 'U', 'v' => 'V', 'w' => 'W', 'x' => 'X',
'y' => 'Y', 'z' => 'Z'
);
$string = file_get_contents("file.txt");
echo custom_ucwords($map, $string);
?>
put words in a file called file.txt visit php ina browser
__________________
hatisblack at yahoo.com |
|
|
|
|
|
#6 | |
|
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
Too lazy to set a custom title
Join Date: Mar 2002
Location: Australia
Posts: 17,393
|
Quote:
If not then replacing \n with <br>\n on the third last line should do the trick. |
|
|
|
|
|
|
#8 |
|
Confirmed User
Join Date: Mar 2003
Posts: 187
|
Use ucwords($string);
__________________
icq 214 - 625 - 815 |
|
|
|
|
|
#9 |
|
<&(©¿©)&>
Industry Role:
Join Date: Jul 2002
Location: Chicago
Posts: 47,882
|
wtf are you guys smoking?
<?php $file=file('somefiletxt'); $file=array_map('strtolower',$file); $file=array_map('ucwords',$file); echo implode('',$file); ?>
__________________
Custom Software Development, email: woj#at#wojfun#.#com to discuss details or skype: wojl2000 or gchat: wojfun or telegram: wojl2000 Affiliate program tools: Hosted Galleries Manager Banner Manager Video Manager ![]() Wordpress Affiliate Plugin Pic/Movie of the Day Fansign Generator Zip Manager |
|
|
|