Jump to content

[SOLVED] How to replace a number/section of a string?


virtuexru

Recommended Posts

preg_replace

 

Would be the easiest. I am not great at regex but it would be something like:

 

<?php
$description = "Please call 917-000-0000. Than you.";
$replacement = ""; // replace it with nothing

$description = preg_replace('/\d/', $replacement, $description);

echo $description;
?>

 

I highly doubt that will work, but that is the idea. Just note the above code will not replace the "-" in the number.

Figured out it using that, thank you. Here was my final code:

 

<?php
  // remove number
  $string          = $content;
  $pattern       = '/718-555-5454/';
  $replacement = "001-203-509-1105"; // replace it with nothing

  $description   = preg_replace($pattern, $replacement, $string);	
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.