Jump to content


Photo

convert to preg_replace


  • Please log in to reply
3 replies to this topic

#1 point3d

point3d

    Newbie

  • Member
  • Pip
  • 6 posts
  • Main OS: Windows Vista

Posted 23 June 2011 - 06:08 AM

How can I convert this to preg_replace?
$TEMPLATE_PATH = ereg_replace("(/)+" ,"/",$TEMPLATE_PATH);

Thanks!

#2 Coral

Coral

    Junior Member

  • Member
  • Pip
  • 40 posts
  • Main OS: Windows XP

Posted 23 June 2011 - 02:33 PM

The regex uses / as the delimiter when searching for / you escape it like so \/ see example test code

<?php
$TEMPLATE_PATH ="c://test//example/////test.php";
print $TEMPLATE_PATH;
$TEMPLATE_PATH = ereg_replace("(/)+" ,"/",$TEMPLATE_PATH);	  //----Deprecated
$TEMPLATE_PATH = preg_replace('/(\/)+/', '/', $TEMPLATE_PATH);
print $TEMPLATE_PATH;
?>
:(

#3 point3d

point3d

    Newbie

  • Member
  • Pip
  • 6 posts
  • Main OS: Windows Vista

Posted 23 June 2011 - 08:25 PM

Thank you very much! :(

#4 point3d

point3d

    Newbie

  • Member
  • Pip
  • 6 posts
  • Main OS: Windows Vista

Posted 24 June 2011 - 03:59 AM

Almost finished the fix for php 5.3
But stuck with this "Easy-to-Read" code :(

$REP_UNDSCR="&amp;|&nbsp;";
  $REP_SPACE="\?|%|'|\"|'|%|/|\||&quot;|\*|#|\^|{|}|;|!|:|~|`|<|>|&lt;|&gt;|,|\\|\(|\)";
  $ADDITIONAL_VAL = ereg_replace($REP_UNDSCR,'_',$ADDITIONAL_VAL);
  $ADDITIONAL_VAL = ereg_replace($REP_SPACE,'',$ADDITIONAL_VAL);

Someone can help to convert this to preg_replace




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users