PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
  Classes of Schroetter Christian  >  PHP String Cut  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Sample file
Class: PHP String Cut
Cut, remove or extract parts of a text string
Author: By
Last change:
Date: 5 years ago
Size: 4,336 bytes
 

 

Contents

Class file image Download
<?php
   
// function's list...
    // QuickDecoupe / QD
    // QuickDecoupeME
    // RemoveString
    // QuickDecoupeSingle / QDS
    // QDSTag
    // QuickDecoupeSingleME
    // QuickDecoupeFromBegin / QDBegin
    // QuickDecoupeToEnd / QDEnd

   
include('./string.cut.class.php');

   
$content = file_get_contents('./sample_content.txt');

    echo
"\t" . 'Return ALL the string between \'<div>\' AND \'</div>\'' . "\n";
   
$offset = 0;
   
$sample_string_1 = CStringCut::QuickDecoupe($content, '<div>', '</div>', $offset); // same as CStringCut::QD(...)
   
while($sample_string_1 !== false)
    {
       
var_dump($sample_string_1);

       
$sample_string_1 = CStringCut::QuickDecoupe($content, '<div>', '</div>', $offset); // same as CStringCut::QD(...)
   
}
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the the string between \'<div>\' AND the third occurence of \'</div>\'\'$offset\'' . "\n";
   
$offset = strpos($content, 'This is my title');
   
$sample_string_2 = CStringCut::QuickDecoupeME($content, '<div class="class_1">', '</div>', $offset, 3);
   
var_dump($sample_string_2);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Remove all the string + the delimiter between \'<div>\' and \'</div>\'' . "\n";
   
$store = $content;
    while(
strpos($store, '<div>') !== false && strpos($store, '</div>') !== false)
    {
       
$store = CStringCut::RemoveString($store, '<div>', '</div>', true);
    }
   
var_dump($store);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the string between \'<title>\' and \'</title>\'' . "\n";
   
$title = CStringCut::QuickDecoupeSingle($content, '<title>', '</title>'); // same as CStringCut::QDS(...)
   
var_dump($title);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the string between \'<div class="class_1">\' and \'</div>\'' . "\n";
   
$sample_string_3 = CStringCut::QDS($content, '<div class="class_1">', '</div>');
   
var_dump($sample_string_3);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the TAGS between \'<div class="class_1"\' and \'</div>\'' . "\n";
   
$offset = 0;
   
$sample_string_3 = CStringCut::QDSTag($content, '<div class="class_1">', '</div>', $offset);
   
var_dump($sample_string_3);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the TAGS between \'<div class="class_1"\' and \'</div>\' AND remove the remains of the initial tag' . "\n";
   
$offset = 0;
   
$sample_string_4 = CStringCut::QDSTag($content, '<div class="class_1">', '</div>', $offset, true);
   
var_dump($sample_string_4);
   
// can be iterat as QuickDecoupe(...)
    /*
        $offset = 0;
        $sample_string_4 = CStringCut::QDSTag($content, '<div class="class_1">', '</div>', $offset, true);
        while($sample_string_4 !== false)
        {
            var_dump($sample_string_4);

            $sample_string_4 = CStringCut::QDSTag($content, '<div class="class_1">', '</div>', $offset, true);
        }
    */
   
echo '----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the STRING between \'[\' and \']\'' . "\n";
   
$offset = 0;
   
$sample_string_5 = CStringCut::QDSTag($content, '[', ']', $offset, false, true);
   
var_dump($sample_string_5);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the the string between \'<div>\' AND the third occurence of \'</div>\'' . "\n";
   
$sample_string_6 = CStringCut::QuickDecoupeSingleME($content, '<div class="class_1">', '</div>', 3);
   
var_dump($sample_string_6);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the the string between offset 0 AND \'<div class="class_1">\'' . "\n";
   
$sample_string_7 = CStringCut::QuickDecoupeFromBegin($content, 0, '<div class="class_1">'); // same as CStringCut::QDBegin(...)
   
var_dump($sample_string_7);
    echo
'----------------------------------------------------------' . "\n";

    echo
"\t" . 'Return the the string between \'<div class="class_1">\' (starting at offset $offset) AND the end of the string' . "\n";
   
$offset = 0;
   
$sample_string_8 = CStringCut::QuickDecoupeToEnd($content, '<script>', $offset); // same as CStringCut::QDEnd(...)
   
var_dump($sample_string_8);
    echo
'----------------------------------------------------------' . "\n";

?>