Tokenize and Revert text - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Tokenize and Revert text.php
- <?php
- $regex = "/((0?[1-9]|[12]\d|3[01])[\/](0?[1-9]|[12]\d|3[01])[\/](19|20)\d{2})/im";
- $text = "12/12/2015 31/12/2019 caraota 12/12/2018";
- // $message = preg_replace($regex, '', $text);
- $datesTokens = [];
- $out = preg_replace_callback(
- $regex,
- function($m) use (&$datesTokens) {
- static $id = 0;
- $id++;
- $datesTokens[] = $m[1];
- return "{date_".$id."}";
- },
- $text);
- echo $text;
- echo "<br>";
- echo $out;
- $out = preg_replace_callback(
- '/{date_[1-9]}/mi',
- function($m) use (&$datesTokens) {
- static $id = -1;
- $id++;
- return $datesTokens[$id];
- },
- $out);
- echo "<br>";
- echo $out;
- echo "<br>";
File Description
- Tokenize and Revert text
- PHP Code
- 12 Sep-2019
- 664 Bytes
You can Share it:
Latest PHP Pastes