Jump to content

[SOLVED] Help with str_replace/preg_replace and numerical wildcards


SuperKas

Recommended Posts

Hi there  ;D

 

I have a set of figures on a webpage, i want to keep one row of them and blank out the rest.

 

I have tried with this code:

 

$html = str_replace("<b>21</b><br />","",$html);
$html = str_replace("<b>31</b><br />","",$html);

 

to blank out this:

 

*random 2 digit value* 21

*random 5 digit value* 10070

*random 2 digit value* 31

 

But as the values in the above code are changing every day, it is no help. I have heard of preg_replace, numerical values and wildcards will help me i'm told,  but i have not used it yet and don't know how the structure works.

 

How would i keep the 5 digit number and blank out the other 2 digit numbers? Any help would be fantastic.

 

Thank you.

Im no regex expert so im sure somebody else will give a better code, but thats all i know and it works for what ure aiming:

 

<?php
$html = "<b>21</b><br />";
$html .= "<b>10070</b><br />";
$html .=  "<b>31</b><br />";;
$html = preg_replace("/<b>.{2}<\/b><br \/>/", '', $html);
echo $html;
?>

Im no regex expert so im sure somebody else will give a better code, but thats all i know and it works for what ure aiming:

 

<?php
$html = "<b>21</b><br />";
$html .= "<b>10070</b><br />";
$html .=  "<b>31</b><br />";;
$html = preg_replace("/<b>.{2}<\/b><br \/>/", '', $html);
echo $html;
?>

 

Mate, that worked straight up. I been fiddling about with

 

$html = preg_replace("(^[0-9]{5})", "", $html);

 

and variations of it for about 2 hours or more. Thank you so much.

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.