NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Alternating string splits

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-10-2005, 10:01 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Jan 2005
Location: Texas USA
Posts: 71
Outer is an unknown quantity at this point
 



Alternating string splits


I need to know how to break a string up into alternating sizes.

for example, I need this string broken up: "hi, how are you, peace!"
so results are like this:
"hi"
", h"
"ow"
" ar"
" y"
"ou "
", p"
"eac"
"e!"

Note the spaces. Basically, I need a string to be cut up by a pattern of 2 characters, then 3 characters, then 2 characters, then three characters

How would I do that in PHP?

Thank You
__________________
I wonder...
Outer is offline  
Old 08-11-2005, 04:05 AM   #2 (permalink)
NamePros Member
 
Icespadez's Avatar
Join Date: Apr 2005
Location: Boston, MA
Posts: 26
Icespadez is an unknown quantity at this point
 



Try this (I think you forgot the 'e' in 'are' in your example =P)

PHP Code:

    $string 
'hi, how are you, peace!';

    function 
customSplitString($text) {
        
$text_pieces = array();
        
$offset 0;
        
$piece_length 2;
        
$str_length strlen($text);
        
        for (
$x=0$offset $str_length$x++) {
            
$piece_length = ($x 2) ? 2;
            
$text_pieces[] = substr($text$offset$piece_length);
????: NamePros.com http://www.namepros.com/programming/114603-alternating-string-splits.html
            
$offset += $piece_length;
????: NamePros.com http://www.namepros.com/showthread.php?t=114603
        }
        return 
$text_pieces;
    }

    
print_r(customSplitString($string)); 
Icespadez is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking php function to strip invalid characters from string RJ Programming 9 04-01-2005 12:34 AM
XML return string namescanada Programming 0 02-16-2005 03:11 PM
PHP Help Needed (String Manipulation) 100 NB Awarded DomainSpring Programming 5 09-05-2004 01:46 AM
String parsing prob, special characters web guru Programming 2 10-03-2003 12:50 PM
VeriSign splits off domain registrar. Jeff Industry News 0 06-17-2003 08:59 PM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:50 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger