|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
strrchr() Question
I've been using PHP for MySQL data retrieval for a while now. I'm decided to dive in and play some more.
I want to Manipulate a Text File and I've used strrchr() to find the last occurence of the string "INITIAL". My question is, why does it echo missing the first few letters? $fcontents = strrchr($fcontents, "INITIAL"); |
|
#2
|
|||
|
|||
|
RE: strrchr() Question
When you use strrchr, it actually only uses one character (the first one in your string in this case) to do it's matching. So, it is actually finding the SECOND 'I' in INITIAL as the last occurrence. And then displaying 'ITIAL' because of that.....
So, how can you accomplish what you want? Well, you could use explode() to break the string down and then just use the last element of the returned array to display what you want (adding 'INITIAL' to the beginning of this last element. Or, you could do something with strstr(), which returns all of a string after the first occurence of a searched string. With this, you could even build a recursive function to bring back the last portion... Hope that gives you a couple ideas... |
|
#3
|
|||
|
|||
|
RE: strrchr() Question
Thanks!
I used strstr() at first, but the string "INITIAL" may or may not come up more than once. If so, can I use a loop statement? And if so, let's say "INITIAL" comes up 4x how do I apply that dynamic 4 to the while() or for() loop? |
|
#4
|
|||
|
|||
|
RE: strrchr() Question
|
|
#5
|
|||
|
|||
|
RE: strrchr() Question
Thanks Matt!!
Pretty Cool, just need to get familiar with these new functions. All in all, PHP is just like any other language. I'm sure more questions on relative functions will come to mind! |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > strrchr() Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|