PHP Classes

Ok, thats a good class !! But as append strings in php is ver...

Recommend this page to a friend!

      String Builder  >  All threads  >  Ok, thats a good class !! But as...  >  (Un) Subscribe thread alerts  
Subject:Ok, thats a good class !! But as...
Summary:Package rating comment
Messages:7
Author:Josť Filipe Lopes Santos
Date:2008-07-17 12:26:15
Update:2009-01-16 13:16:58
 

Josť Filipe Lopes Santos rated this package as follows:

Utility: Good
Consistency: Good
Examples: Good

  1. Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Josť Filipe Lopes Santos Josť Filipe Lopes Santos - 2008-07-17 12:26:15
Ok, thats a good class !!
But as append strings in php is very easy, do not compensates makes this class ... !!
Example: echo "hello"."<br>"."world !"."<br>"."bye" appends strings easily, and dont have restriction in the number of strings to append
But ..... its so a suggestion ... !! lool

  2. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Senad Meskin Senad Meskin - 2008-07-17 13:13:02 - In reply to message 1 from Josť Filipe Lopes Santos
Appending string in php or any other script or programming language is very slow if you don't append it on low level.
function sprintf is made to append strings faster....
$car = 'car';
$state = 'cool';
$string = sprintf('this %s is very %s), $car, $cool);
//is faster than
$string = 'this' . $car . ' is very ' . $state;

  3. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Senad Meskin Senad Meskin - 2008-07-17 13:19:10 - In reply to message 2 from Senad Meskin
Appending string in php or any other script or programming language is very slow if you don't append it on low level.
function sprintf is made to append strings faster....
$car = 'car';
$state = 'cool';
/**syntax error in previous post
$string = sprintf('this %s is very %s', $car, $cool);
//is faster than
$string = 'this' . $car . ' is very ' . $state;

appending strings in sprintf is much more faster...

  4. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Josť Filipe Lopes Santos Josť Filipe Lopes Santos - 2008-07-17 14:11:01 - In reply to message 3 from Senad Meskin
i've dont know that the sprintf if fastest than echo .... !! looool
But in the most scripts, programmers using echo .... !!

  5. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Senad Meskin Senad Meskin - 2008-07-17 14:26:07 - In reply to message 4 from Josť Filipe Lopes Santos
OK!
I want to explain.
$string = sprintf('%s and so on %s', 'first', 'second');
$string2 = 'first' . ' and so on ' . ' second ';
concating $string is faster than concating $string2
echo is for output, that is not concate

If you want to concate string in the way you say this is what is going on to PHP
ex. for string 'first' . ' and so on ' . ' second ';
-- init string for echo
-- init string for 'first'
-- add to first string
-- init string ' and so on '
-- add string to first string
-- init string for ' second ';
-- add string to frist string;
-- return string to echo;
that is much slower...
echo is not for concating strings, echo is used to send string to output.

  6. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of yaron tal yaron tal - 2009-01-16 10:35:02 - In reply to message 5 from Senad Meskin
I did some testing and it looks like sprintf is slower than just concat by using ''.''.$var.''.

pastebin.com/f226b89aa
I used that to test, and it looks like sprintf is almost 10x slower.

  7. Re: Ok, thats a good class !! But as...   Reply   Report abuse  
Picture of Senad Meskin Senad Meskin - 2009-01-16 13:16:58 - In reply to message 6 from yaron tal
Thank you for your replay.
Good stuff to know. I will try to change this class a little more

 
For more information send a message to info at phpclasses dot org.