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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-09-2008, 04:31 AM   #1
mkx
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?
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-09-2008, 04:50 AM   #2
farkedup
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 --
farkedup is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-09-2008, 04:52 AM   #3
farkedup
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 --
farkedup is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-09-2008, 04:56 AM   #4
rowan
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++;
}
It's late, it's messy, but it should work
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-09-2008, 05:01 AM   #5
SmokeyTheBear
►SouthOfHeaven
 
SmokeyTheBear's Avatar
 
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);
?>
save as do.php

put words in a file called file.txt

visit php ina browser
__________________
hatisblack at yahoo.com
SmokeyTheBear is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2008, 05:57 AM   #6
mkx
Confirmed User
 
Industry Role:
Join Date: Nov 2003
Location: Toronto
Posts: 4,001
Quote:
Originally Posted by rowan View Post
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++;
}
It's late, it's messy, but it should work
This worked but it puts it all on the same line. I am a donkey so I don't know how to create a new line in php for this script. Tried <br> and another \n but nothing
mkx is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2008, 06:37 AM   #7
rowan
Too lazy to set a custom title
 
Join Date: Mar 2002
Location: Australia
Posts: 17,393
Quote:
Originally Posted by mkx View Post
This worked but it puts it all on the same line. I am a donkey so I don't know how to create a new line in php for this script. Tried <br> and another \n but nothing
If you're running it as a WEB server script (ie loading blah.php with your browser) then that's easy - view the source of the page

If not then replacing \n with <br>\n on the third last line should do the trick.
rowan is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2008, 08:50 PM   #8
dekaz
Confirmed User
 
Join Date: Mar 2003
Posts: 187
Use ucwords($string);
__________________
icq 214 - 625 - 815
dekaz is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-15-2008, 09:13 PM   #9
woj
<&(©¿©)&>
 
woj's Avatar
 
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
woj is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.