Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-04-2004, 04:12 PM   #1 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
Flat Explode

heres a good php trick. you cant explode an array with a null divider which can get annoying but using chunk_split can get arround that...

function flatExplode($safeCharacter, $String) {
$exploded = explode($safeCharacter, chunk_split($String, 1, $safeCharacter));
unset($exploded[strlen($String)]);
return($exploded);
}

just make $sting what you want to be exploded, and a character that you know isnt in the $string, like /xff for example. if you may wonder what youd need to do this for, you can make a sentence capitaler using this. using a for each on the $exploded, and runing some if statements.
falsepride is offline   Reply With Quote
Old 11-04-2004, 04:23 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
interesting post. thanks. you should include the logic to make the sentence capitalizer and create a new article

here's another cool way...
PHP Code:
<?
function FixTextCase($text) {
    
$text strtolower($text);
    
$sentences preg_split("/(\.(\s)?|\?(\s)?)/",$text,-1,PREG_SPLIT_DELIM_CAPTURE);
   
    foreach(
$sentences as $x) {
        if ((
trim($x) == ".") || (trim($x) == "?")) {
            
$outtext .= trim($x)." ";
        } else {
            
$outtext .= ucfirst(trim($x));
        }
    }
   
    
// fix double mark errors
    
$outtext preg_replace("/(\s\.)/",".",$outtext);
    
$outtext preg_replace("/(\s\?)/","?",$outtext);
    return 
$outtext;
}

$string "this is a test. IS THIS A TEST? YES it is a test.";

echo 
FixTextCase($string);
?>
__________________
Mike
sde is offline   Reply With Quote
Old 11-04-2004, 04:40 PM   #3 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 209
falsepride is on a distinguished road
never knew about the ucfirst command existed, but my way of doing it would have been
PHP Code:
foreach ($exploded as $e) {
if(
$three == "yes") {
$e strtoupper($e);
$one "";
$two "";
$three "";
}
if ((
$two == "yes") && ($e == " ")) {
$three "yes";
}
if ((
$one == "yes") && ($e == " ")) {
$two "yes";
}
if(
$e == "." || $e == "?" || $e == "!") {
$one "yes"
}


Last edited by sde; 11-04-2004 at 06:00 PM.
falsepride is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 04:44 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting