PHP Classes

PHP Marker: Replace marks in text with given values

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (9 months ago) RSS 2.0 feedNot enough user ratingsTotal: 135 All time: 9,286 This week: 673Up
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 is available for providing paid consulting. Contact Radovan Janjic .
Classes: 14 packages by
Country: Serbia Serbia
Age: 36
All time rank: 2382 in Serbia Serbia
Week rank: 50 Up1 in Serbia Serbia Up
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 (3)  
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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:135
This week:0
All time:9,286
This week:673Up