List Info

Thread: note 78473 added to reference.pcre.pattern.syntax




note 78473 added to reference.pcre.pattern.syntax
user name
2007-10-13 12:32:24
I use these functions all the time:

<?php

function regexpmetaspecialchars($ps_str, $ps_delimiter =
'/') {
  $ha_replsearch = array('\', '^', '$', '.', '[', ']', '|',
'(', ')', '?', '*', '+', '{', '}', $ps_delimiter);
  $ha_replreplace = array('\\', '\^', '\$', '\.',
'\[', '\]', '\|', '\(', '\)', '\?', '\*', '\+',
'\{', '\}', '\' . $ps_delimiter);

  return str_replace($ha_replsearch, $ha_replreplace,
$ps_str);
  }

function regexpmetabracketspecialchars($ps_str,
$ps_delimiter = '/') {
  $ha_replsearch = array('\', '^', '-', ']',
$ps_delimiter);
  $ha_replreplace = array('\\', '\^', '\-', '\]', '\'
. $ps_delimiter);

  return str_replace($ha_replsearch, $ha_replreplace,
$ps_str);
  }

function regexpmetareplacespecialchars($ps_str) {
  $ha_replsearch = array('\', '$');
  $ha_replreplace = array('\\', '\$');

  return str_replace($ha_replsearch, $ha_replreplace,
$ps_str);
  }

// Function aliases:
//
function regexpspecialchars($ps_str, $ps_delimiter = '/') {
  return regexpmetaspecialchars($ps_str, $ps_delimiter =
'/');
  }
function regexpbracketspecialchars($ps_str, $ps_delimiter =
'/') {
  return regexpmetabracketspecialchars($ps_str,
$ps_delimiter = '/');
  }
function regexpreplacespecialchars($ps_str) {
  return regexpmetareplacespecialchars($ps_str);
  }

?>
----
Server IP: 194.145.210.3
Probable Submitter: 82.153.209.218
----
Manual Page -- http://www.php.net/manual/en/reference.pcre.patter
n.syntax.php
Edit        -- https://master
.php.net/note/edit/78473
Del: integrated  -- h
ttps://master.php.net/note/delete/78473/integrated
Del: useless     -- http
s://master.php.net/note/delete/78473/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78473/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78473/spam
Del: non-english -- 
https://master.php.net/note/delete/78473/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78473/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78473
Reject      -- https://mast
er.php.net/note/reject/78473
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )