str_replace question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MiniMonty
Forum Contributor
Posts: 196
Joined: Thu Sep 03, 2009 9:09 am
Location: UK

str_replace question

Post by MiniMonty »

Hi all,

I am using .txt file to tell a Flash front end all kinds of stuff and it works fine.

One issue is that a certain string in a txt file is regularly updated. The the last line reads:
&totalimgs=12 where the number 12 is always changing (upward).

I am using str_replace to strip out the line &totalimgs= but what do I add to take out
the number that follows it which could be up to five digits ?

Best wishes
Monty
User avatar
Weiry
Forum Contributor
Posts: 323
Joined: Wed Sep 09, 2009 5:55 am
Location: Australia

Re: str_replace question

Post by Weiry »

I couldn't tell you exactly how to do it. But i believe you would need to perform some sort of a regular expression on the remaining string for up to the next 5 numbers. Then if it meets a character not an object, the script stops.
A far less efficient method would be to explode the remaining string, then loop through each singular character to check if its a number (for up to 5) and extract it.
I am not very familiar with regex code though, but thats how i believe it would be done efficiently.
Post Reply