Truncate String |
[eluser]xwero[/eluser]
ok i will check it out, it's friday anything can happen ![]()
[eluser]xwero[/eluser]
i used this code to check Code: $in = "Hey coding is fun <|more|> I love it."; Quote:Small -> Hey coding is funIt works as expected. Can you show the code you used to check it?
[eluser]Yash[/eluser]
my bad.. This time it works nicely.I guess this is best time saving algo. mate you are really champ... Thank you so much xwero.
[eluser]Yash[/eluser]
Your code perfectly with one line..If I change my content to "<p>Expert Vision is a free, tableless, W3C-compliant web design layout by <span>Speedovation</span>. This template has been tested and proven compatible with all major browser environments and operating systems. You are free to modify the design to suit your tastes in any way you like.</p> <|more|> <p>We only ask you to not remove <span>"Design by Speedovation"</span> and the link http://www.speedovation.com from the footer of the template.</p> <p>If you are interested in seeing more of our free web template designs feel free to visit our website, Speedovation. We intend to add at least 25 new free templates in the coming month.</p>" now it fails........showing all values
[eluser]xwero[/eluser]
Code: preg_replace('/\<\|more\|\>.+/m','',$in); regular expressions are the perl inside php, one line packs a whole lot of power but you can only understand it if you know the language ![]()
[eluser]Yash[/eluser]
I know VB.NET regular expression and a little in php ... anyways thank you bro...
[eluser]sophistry[/eluser]
I wrote up a test file. it is at http://codeigniter.com/wiki/String_Parsing_Test_Code/. conclusion: ------------------ substr() approach is best overall - it is fast with small strings (preg_replace is the fastest). substr() stays fast no matter how large the input string gets (the other techniques slow with progressively longer strings). here are the four approaches i tested: Code: function preg_rep_cut($in,$split_at_regex) Code: Array enjoy. :coolsmile: |
Welcome Guest, Not a member yet? Register Sign In |