SuperKas Posted April 26, 2008 Share Posted April 26, 2008 Hi there 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. Link to comment https://forums.phpfreaks.com/topic/103062-solved-help-with-str_replacepreg_replace-and-numerical-wildcards/ Share on other sites More sharing options...
Fadion Posted April 26, 2008 Share Posted April 26, 2008 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; ?> Link to comment https://forums.phpfreaks.com/topic/103062-solved-help-with-str_replacepreg_replace-and-numerical-wildcards/#findComment-527997 Share on other sites More sharing options...
moselkady Posted April 26, 2008 Share Posted April 26, 2008 If you just want to remove any line with a 2-digit number, you can try this: $html = ereg_replace("<b>[0-9]{2}</b><br />","",$html); Link to comment https://forums.phpfreaks.com/topic/103062-solved-help-with-str_replacepreg_replace-and-numerical-wildcards/#findComment-527998 Share on other sites More sharing options...
SuperKas Posted April 26, 2008 Author Share Posted April 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103062-solved-help-with-str_replacepreg_replace-and-numerical-wildcards/#findComment-528019 Share on other sites More sharing options...
SuperKas Posted April 26, 2008 Author Share Posted April 26, 2008 If you just want to remove any line with a 2-digit number, you can try this: $html = ereg_replace("<b>[0-9]{2}</b><br />","",$html); I think i got it sorted, thank you moselkady Link to comment https://forums.phpfreaks.com/topic/103062-solved-help-with-str_replacepreg_replace-and-numerical-wildcards/#findComment-528022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.