WEB DEVELOPMENT

php Strings

Miscellaneous Gibberish

     
function fvckery($tofindparsereturn){
    
    //returns a numerical start point for $php ---> 7
    strpos("I love $php, I love $php too!", "$php");
    
    //Search a string for "world", and return all characters from this position to the end of the string:
    strrchr("Hello world!","world");
    
    //Find the position of the last occurrence of "php" inside the string:
    strrpos("I love php, I love php too!","php");
    
    //Find the position of the last occurrence of "php" inside the string:
    echo strripos("I love php, I love php too!","PHP");
    
    //returns the number of characters ---> 5
    strlen("Hello");
    
    //Replace the characters "world" in the string "Hello world!" with "Peter":
    str_replace("world","Peter","Hello world!");
    htmlspecialchars($parsedString);
    
    //Replace "Hello" with "world":
    substr_replace("Hello","world",0);
    
    //Count the number of times "world" occurs in the string:
    substr_count("Hello world. The world is nice","world");
    
    //Replace the characters "ia" in the string with "eo":
    strtr("Hilla Warld","ia","eo");
    
    //Split string one by one:
    $string = "Hello world. Beautiful day today.";
    $token = strtok($string, " ");
    
    //Find the first occurrence of "world" inside "Hello world!" and return the rest of the string:
    echo strstr("Hello world!","world");
    
    //Find the first occurrence of "world" inside "Hello world!", and return the rest of the string:
    stristr("Hello world!","WORLD");
    
}



function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}



function replace_between($str, $needle_start, $needle_end, $replacement) {
    $pos = strpos($str, $needle_start);
    $start = $pos === false ? 0 : $pos + strlen($needle_start);

    $pos = strpos($str, $needle_end, $start);
    $end = $pos === false ? strlen($str) : $pos;

    return substr_replace($str, $replacement, $start, $end - $start);
}



function tag_contents($string, $tag_open, $tag_close){
   foreach (explode($tag_open, $string) as $key => $value) {
       if(strpos($value, $tag_close) !== FALSE){
            $result[] = substr($value, 0, strpos($value, $tag_close));
       }
   }
   return $result;
}