Jump to content

strpos, strlen, substr problem. pls help me


gudfry

Recommended Posts

hello to all;

 

              I' have litle problem with some php stuff, I had created a function for strpos, substr, strlen which inserted to the turnword.php. here some of my code.

processline.php

 

<?php

 

function processLine($line) {

 

if(strpos($line,'/* $')===0) {

// chexk for the ':'

if(strpos($line,':')>=5) {

// check for the ending '*/'

 

if (strpos($line,'*/')>=6) {

 

$retval=Array();

 

  $positionOfColon=strpos($line,":");

    $lengthOfString0Ineed=$positionOfColon-4;

    $retval[0]=substr($line,4,$lengthOfString0Ineed);

  $retval[1]=substr($line,$positionOfColon+1,strlen($line)-$positionOfColon-3);

 

return $retval;

}

else { // third condition not met

return false;

 

}

}

else { // no match for '/* $' at the beginning of the line

return false;

}

}

}

?>

 

the code above well insert into turnword.php to read the multi-comment line.

 

turnword.php

 

<?php

            require_once('processline.php');

 

            /* $Author : Chad */ this will return Author : Chad

              /* Author : chad */ this will return false

 

              /* $chad : Author */ this will retun chad : Author.

 

              /* $ : Chad */ this will return false.

 

              /* : Chad /* this will retun false.

 

              /* $Author : */ this will return false.

 

              /* $chad :  */ this will return false.

 

// this function will return a whole string to reverse.

function turnwords($string) {

 

// below

 

$result=strrev($string);

 

// above

return $result;    

}

 

$result=turnwords('DEF');

echo '<p>'.($result).'</p>';

 

    ?>

 

      hope you have idea with this.

 

       

 

:?:  :?:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.