nicob Posted August 30, 2008 Share Posted August 30, 2008 Hello, I have something like this str_replace("\n<font style=\x22font-size: ??px;\x22><a href=\x22http://www.domain.com/search.php?query=\x22></a></font></br> ", "", etc... The problem is that I don't know wich number '??' will be. But I know it has 2 digits. Now How can I tell PHP to replace the whole sentence even I don't know the numbers??? THX Quote Link to comment https://forums.phpfreaks.com/topic/122028-replace-numbers-problem/ Share on other sites More sharing options...
tibberous Posted August 30, 2008 Share Posted August 30, 2008 Regex. echo preg_replace("/\d\dpx/", '[bOOM!]', "\n<font style=\x22font-size: 16px;\x22><a href=\x22http://www.domain.com/search.php?query=\x22></a></font></br>"); Quote Link to comment https://forums.phpfreaks.com/topic/122028-replace-numbers-problem/#findComment-629899 Share on other sites More sharing options...
nicob Posted August 31, 2008 Author Share Posted August 31, 2008 @tibberous Thanks for you answer, but I could not find a solution yet. I have tried other regex solutions, but it's not easy. My script must do this: I have a file with search actions from users. It collects information in this format, and it's for my eyes only, <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 16px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 30px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 14px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 10px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 28px;"><a href="http://www.domain.com/search.php?query="></a></font></br> You see that some lines contain incomplete information. So I have another script that filter those lines out (and also the duplicates), so I won't see empty lines in my html file. BUT the problem is that I use different font size, and I hope there is a easy way to tell php to just ignore those two digits (it's a number between 15-30) and find the dups and empty lines. Example of my code, <?php $page = "/home/website/domains/domain.com/public_html/outputdata.txt"; $nodups = array_unique (explode ("\n", str_replace("\n<font style=\x22font-size: 15px;\x22><a href=\x22http://www.domain.com/search.php?query=\x22></a></font></br> ", "", file_get_contents($page)))); echo implode("\n",array_slice($nodups,-101,100)); ?> You see '15' (px), but that 15 could also be '28'... Anyone with a tip? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/122028-replace-numbers-problem/#findComment-630142 Share on other sites More sharing options...
sasa Posted August 31, 2008 Share Posted August 31, 2008 try <?php $page = '<font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 16px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 30px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 14px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 10px;"><a href="http://www.domain.com/search.php?query=keyword">keyword</a></font></br> <font style="font-size: 28px;"><a href="http://www.domain.com/search.php?query="></a></font></br> '; $nodups = array_unique (explode ("\n", preg_replace("/\d\dpx/", "20px", $page))); echo implode("\n",array_slice($nodups,-101,100)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/122028-replace-numbers-problem/#findComment-630241 Share on other sites More sharing options...
nicob Posted August 31, 2008 Author Share Posted August 31, 2008 @Sasa I have tried your code out, and it changes all font size to '20'. But I want to keep the different sizes... Your code helped me to make the next one <?php $page = "/home/website/domains/domain.com/public_html/outputdata.txt"; $nodups = array_unique (explode ("\n", str_replace("\n<font style=\x22font-size: ".preg_match('/\d\dpx/', '')."px;\x22><a href=\x22http://www.domain.com/search.php?query=\x22></a></font></br> ", "", file_get_contents($page)))); echo implode("\n",array_slice($nodups,-101,100)); ?> Now I don't see the lines without a keyword. example before: <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query=car">car</a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query=boat">boat</a></font></br> <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 16px;"><a href="http://www.domain.com/search.php?query=php+freaks">php freaks</a></font></br> <font style="font-size: 30px;"><a href="http://www.domain.com/search.php?query=house+for+sale">house for sale</a></font></br> <font style="font-size: 14px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 22px;"><a href="http://www.domain.com/search.php?query=boat">boat</a></font></br> <font style="font-size: 10px;"><a href="http://www.domain.com/search.php?query=games">games</a></font></br> <font style="font-size: 28px;"><a href="http://www.domain.com/search.php?query="></a></font></br> <font style="font-size: 14px;"><a href="http://www.domain.com/search.php?query=car">car</a></font></br> example after the last change: <font style="font-size: 20px;"><a href="http://www.domain.com/search.php?query=car">car</a></font></br> <font style="font-size: 17px;"><a href="http://www.domain.com/search.php?query=boat">boat</a></font></br> <font style="font-size: 16px;"><a href="http://www.domain.com/search.php?query=php+freaks">php freaks</a></font></br> <font style="font-size: 30px;"><a href="http://www.domain.com/search.php?query=house+for+sale">house for sale</a></font></br> <font style="font-size: 22px;"><a href="http://www.domain.com/search.php?query=boat">boat</a></font></br> <font style="font-size: 10px;"><a href="http://www.domain.com/search.php?query=games">games</a></font></br> <font style="font-size: 14px;"><a href="http://www.domain.com/search.php?query=car">car</a></font></br> Like you see I still have dups in the file: 'car' and 'boat'. This is because of the different font size, and that makes it not a dupe. I'm not a php expert, but I'm trying to discover the power of php. I'm still impressed, and I believe this is possible! Quote Link to comment https://forums.phpfreaks.com/topic/122028-replace-numbers-problem/#findComment-630338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.