ProXy_ Posted October 7, 2009 Share Posted October 7, 2009 i'm starting to realize some problems with explode. i was really hoping there was another way to do this. Basicly i created a counter that acts off 1 .txt file in this text file there are tons of pages with their counters They look like this: $site-0*end$site Basicly my code grabs the number and adds the hit to it, if visited. Problem i'm getting is this: say one page is: 93.html and another page is 193.html Both of these pages will get pulled. it completely ignores the 1 this is the current code, i would really appreciate any help. $code=file_get_contents("../docs/counter.txt"); $code2=file_get_contents("../docs/counter.txt"); $ex1=explode("$stray3-", $code); $ex2=explode("*end$stray3", $ex1[1]); $nope="0"; $d=$ex2[0]; once again i really appreciate any help offered:) Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/ Share on other sites More sharing options...
btherl Posted October 7, 2009 Share Posted October 7, 2009 You can choose a character which cannot appear in your site name, and "protect" your site name with it. For example, instead of $site-0*end$site you might use |$site|-0*end|$site| Then you explode on "|$site|" instead of just "$site" Or you could store your data like this: $site|counter Then you would explode on "|", and your results would be a site name and a counter. But then you need to find the correct line before exploding - it looks like your current code uses the explode itself to find the entry. Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/#findComment-932176 Share on other sites More sharing options...
salathe Posted October 7, 2009 Share Posted October 7, 2009 Either don't use double quotes, or escape the dollar sign in the explode lines of your code. Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/#findComment-932209 Share on other sites More sharing options...
btherl Posted October 7, 2009 Share Posted October 7, 2009 I don't think he wants the dollar sign escaped. He's substituting a site name into the explode calls so he can find the correct line in the file. Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/#findComment-932294 Share on other sites More sharing options...
salathe Posted October 7, 2009 Share Posted October 7, 2009 Ah fair enough, the OP isn't clear. To the OP: give us an example of the counter file and more of your code (since it appears to just be a snippet that you posted). Does this need to be done with explode or are you open to other techniques? Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/#findComment-932298 Share on other sites More sharing options...
ProXy_ Posted October 7, 2009 Author Share Posted October 7, 2009 You can choose a character which cannot appear in your site name, and "protect" your site name with it. For example, instead of $site-0*end$site you might use |$site|-0*end|$site| Then you explode on "|$site|" instead of just "$site" Or you could store your data like this: $site|counter Then you would explode on "|", and your results would be a site name and a counter. But then you need to find the correct line before exploding - it looks like your current code uses the explode itself to find the entry. Thank you, the method worked great. and easy implication. I appreciate everyone's help Quote Link to comment https://forums.phpfreaks.com/topic/176772-solved-need-alternative-to-explode/#findComment-932504 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.