Jump to content

[SOLVED] Need Alternative to Explode


ProXy_

Recommended Posts

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:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

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.