Need little help

Discussion in 'PHP' started by lmao, Nov 19, 2009.

  1. #1
    Hi,

    I need a little php code that can acheive this

    for example if i enter any keyword like

    $str="MyLapTop";

    it should be converted to a php array

    like

    Array ( [0] => My,[1]=>Lap,[2]=>Top )

    hope that make sense.

    Plz if anyone can help me.
    Thankx for reading this
     
    lmao, Nov 19, 2009 IP
  2. emed

    emed Peon

    Messages:
    70
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hello, this function do what you want:
    <?php
    $str="MyLapTop";
    $res = camelCaseToArray($str);
    
    echo "<pre>";
    print_r($res);
    echo "</pre>";
    
    function camelCaseToArray($text){
    	$text=preg_replace("/([A-Z])/","/#/$1",$text);
    	return explode("/#/",(substr($text,0,3)=="/#/")?substr($text,3):$text);
    }
    PHP:
    output:
    Array
    (
         [0] => My
         [1] => Lap
         [2] => Top
    )
    Code (markup):
     
    Last edited: Nov 19, 2009
    emed, Nov 19, 2009 IP
  3. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just explode the Upper letters..
     
    xenon2010, Nov 19, 2009 IP
  4. lmao

    lmao Guest

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thankx a lot mate +rep given :)
     
    lmao, Nov 20, 2009 IP