Jump to content

[SOLVED] Array Wildcard


iceblox

Recommended Posts

Hi All,

 

I have a replacement script which uses this line to replace data that it matches within a csv file.

 

"£95.00 upfront cash back." => "0", 

 

Is there anyway of changing 95.00 for a wild card? so that i dont have to add every monerty value in?

 

 

Link to comment
Share on other sites

Yes, with regular expressions and preg_replace():

 

<?php
//$file contains file contents as a string

$find = array(
'~£[0-9]{1,2}\.[0-9]{2} upfront cash back\.~'
);
$replace = array(
'0'
);
$file = preg_replace($find, $replace, $file);
?>

 

Instead of searching for 95.00 it searches for 1-2 digits, a dot, and then 2 digits. To search for e.g. 1-3 digits before the dot, use {1,3} instead of {1,2} in the code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.