SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Joining strings in a class

    I have a part of a class where I'm looping through a file and I want to join a couple of strings in a variable. However I can't seem to figure out how to append/join the 10 strings together.
    Here is the code.
    Question is... how can I have the $label variable with 10 lines instead of only the last line?

    PHP Code:
    $Qvar=1;
    $z 0;
    while (
    $z<10){
        
    $z++
        
    $NewQ[$Qvar] = new Question();
        
    $NewQ[$Qvar] -> label $line
        
    $NewQ[$Qvar] -> QText($label) ;
                 
    }             

    $i=0;
    $qvarc count($NewQ);
    while (
    $i $qvarc +1){
        echo 
    '<br /><br />';
        echo 
    '<br /><u>'.$NewQ[$i]->label.'</u>';
        
    $i++;    
    }

                 
    class 
    Question{

            var 
    $label ;

        function 
    QText($line){
        
            
    $label_end_pos strpos($line,".",0);
            
    $label $this->label $label ;
            return 
    $label;
            

         }


  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $Qvar=1;
    $z 0;
    $NewQ[$Qvar] = new Question();
    while (
    $z<10){
        
    $z++
        
    $NewQ[$Qvar] -> QText($label);
                 

    PHP Code:
    class Question{

            var 
    $label ;

        function 
    Question(){
           
    $this->label="";
        }

        function 
    QText($line){
        
            
    $label_end_pos strpos($line,".",0);
            
    $this->label .= substr($line,0,$label_end_pos);
            
        }

    I tried to guess what you're doing it. Even if I failed you get the picture.
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •