Urg yep me again - ran into yet another problem...
I have a variable (some of you may know what project im referring to here) that has many lines of writing in.. i need to remove the first line and the last line...
Now.. im pretty sure im going to have to use an array for this? which is just my fav thing :/.. I studied Perl for 3 years and still didnt like using arrays :| so when it comes to php im even further away
but anyway I still had a go tho without using first and last line of the var as I dont know how to get those things, is there a function for that ?.. but here is my attempt at the array stuff.. "pretending" first line is fLine and last line is lLine..
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
thats great... i tested both.. and they do both work great - tho due to my fear of array's im gonig with raf's... but ive saved the array under a comment in the code for reference
Last question.. would what im using here.. rafs code.. how hard would it be to get it to remove everything, no matter what line number before the first apperance of "whatever" ?
The array-approach is probably slower and more resource eating anyway (i think )
Quote:
Last question.. would what im using here.. rafs code.. how hard would it be to get it to remove everything, no matter what line number before the first apperance of "whatever" ?
Hmm. Seems like you're not realy inderstanding the code.
strpos($var, "\n") returns the position of the first occurence of \n inside the string?
substr returns the part of the string, from the value from the second argument on, until the value of the third argument.
substr($var, 0, 10) returns the first 10 characters
substr($var, 10) return the string from the 11° position on, till the end of the string.
So
$var=substr($var, (strpos($var, "\n")+1));
returns the substring from the first occurence of "\n" + 1
If you replace the "\n" by 'test' then you'll the string from right after 'test' till the end of the string
The array-approach is probably slower and more resource eating anyway
that was my assumption as well , & I just did a few tests & whilst for small strings arrays are no slower ...for larger ones (& not very large either) it slows down considerably, over twice as slow as rafs method
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)