PHP Classes

PHP Marker: Replace marks in text with given values

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (3 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 134 This week: 1All time: 9,265 This week: 348Up
Version License PHP version Categories
php-marker 1.0GNU General Publi...5.0PHP 5, Text processing
Description 

Author

This class can replace marks in text with given values.

It takes a text string to search and replace for given marks defined with regular expressions.

The class can replace several values at once. The number of replaced occorrences can be limited. The class returns the number of replaced occurrences.

The class can also cleanup the text string just removing the original marks.

Picture of Radovan Janjic
  Performance   Level  
Name: Radovan Janjic <contact>
Classes: 14 packages by
Country: Serbia Serbia
Innovation award
Innovation award
Nominee: 3x

Example

<?php
require "Marker.class.php";

$content = <<<TEST
1
<!-- TEST_ONE -->
some content
<!-- / TEST_ONE -->

2
<!-- TEST_TWO -->
some content TEST_TWO
<!-- /TEST_TWO -->

3
<!--TEST_THREE-->
some content
<!--/TEST_THREE-->

4
<!-- TEST_FOUR -->
some content
<!-- / TEST_FOUR -->
we already closed this marker on line above this one
<!-- / TEST_FOUR -->

5
<!-- TEST_FIVE -->
some content
<!-- / TEST_FIVE -->

6
<!-- TEST_SIX / -->

7
<!--TEST_SEVEN/-->
------------------------------------------------------------

TEST;

echo
"1. Example - singe marker" . PHP_EOL;
echo
"------------------------------------------------------------" . PHP_EOL;
echo
Marker::replace($content, 'TEST_ONE', NULL);

echo
"2. Example - arrays of markers and replacements" . PHP_EOL;
echo
"------------------------------------------------------------" . PHP_EOL;
$markers = array();
$replace = array();

$markers[] = 'TEST_ONE';
$replace[] = 'Test one content';

$markers[] = 'TEST_TWO';
$replace[] = 'Test two content';

$markers[] = 'TEST_THREE';
$replace[] = 'Test three content';

$markers[] = 'TEST_FOUR';
$replace[] = 'Test four content';
echo
Marker::replace($content, $markers, $replace);

echo
"3. Example - cleanup" . PHP_EOL;
echo
"------------------------------------------------------------" . PHP_EOL;
echo
Marker::cleanup($content);



Details

PHP_Marker


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Plain text file Marker.class.php Class Class source
Accessible without login Plain text file README.md Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:134
This week:1
All time:9,265
This week:348Up