copy specific string via string pos, and string len

Discussion in 'PHP' started by ironmankho, Nov 29, 2011.

  1. #1
    hi

    i want to copy specific string via string pos, and string len
    i need little help thanks (please not advise me about explode i am already know that it is very easy option for that)


    full string is : World Scientific;Expanded edition

    my need World Scientific

    i write sample code for this

    <?php
      $a='World Scientific;Expanded edition';
      
       $strlen=strlen($a);
       $strpos=strpos($a, ';');
       $strcopy=$strlen-$strpos ;
       echo $strlen.'</br>'; 
       echo $strpos.'</br>';
    ?>
    PHP:
     
    Solved! View solution.
    Last edited: Nov 29, 2011
    ironmankho, Nov 29, 2011 IP
  2. #2
    emm $strpos=strpos($a, ';'); does give 16charactors count excluding ;

    Did you mean to use str_split() aswell
    
    <?php
      
       $a='World Scientific;Expanded edition';
    
       $strpos=strpos($a, ';'); // = 16
    
       $a2 = str_split($a, $strpos); // split the string from 16 charactors
    
    echo $a2[0];  // World Scientific
    
    ?>
    
    PHP:
     
    MyVodaFone, Nov 29, 2011 IP
  3. ironmankho

    ironmankho Active Member

    Messages:
    393
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    Thanks myvodafone..... it is nice solution :eek:
     
    ironmankho, Nov 29, 2011 IP