Jump to content


Photo

preg_replace


  • Please log in to reply
3 replies to this topic

#1 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 12 April 2006 - 12:00 PM

how to replace, \\ to \ and \ to nothing using preg_replace?
if someone knows a tutorial of regular expresions.. tell me...

tks

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 12 April 2006 - 12:11 PM

try this...

<?php
$lookfor = array('/\\\\/','/\\/');
$repwith = array('\\','');

$string = preg_replace($lookfor,$repwith,$string);
?>

where $string is the string you want to do the replacement on.

follow me on twitter @PHPsycho

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 12 April 2006 - 12:17 PM

[!--quoteo(post=363994:date=Apr 12 2006, 08:00 AM:name=wolves)--][div class=\'quotetop\']QUOTE(wolves @ Apr 12 2006, 08:00 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
how to replace, \\ to \ and \ to nothing using preg_replace?
if someone knows a tutorial of regular expresions.. tell me...

tks
[/quote]

[a href=\"http://www.regular-expressions.info\" target=\"_blank\"]http://www.regular-expressions.info[/a]

also, if that's what you're after, why not just use stripslashes()?
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 12 April 2006 - 12:26 PM

[!--quoteo(post=363999:date=Apr 12 2006, 07:17 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Apr 12 2006, 07:17 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]

also, if that's what you're after, why not just use stripslashes()?
[/quote]

yeah, it's make my life easier.. I thought that it will strip all \, but not

tks, all!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users