Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a problem with a program, which puts number "0" before a number converted to String. In C# it works correctly, but in php it throws this error: Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\ProfilHrace.php on line 83. Does anybody know why?

Can anybody solve this problem?

PHP
80 $priceTmp = (string)$select["Price"]; //$select["Price"] returns number correctly
81 while(sizeof($priceTmp)%3 !=0)
82 {
83    $tmp = "0".$priceTmp;  //here it throws an error
84    $priceTmp = $tmp;
85 }</pre>


I can not find any online debugger for php and my debugger doesn't work.

Thanks for replies!
Pepin z Hane
Posted

1 solution

Your problem is that PHP's function sizeof(...) (also an alias on count(...)) returns the number of elements in an array. I guess if you use it on a scalar it will just return 1.
What you need to use here is the int strlen(string $string) function instead: http://php.net/manual/en/function.strlen.php[^]

PHP
80 $priceTmp = (string)$select["Price"]; //$select["Price"] returns number correctly
81 while(strlen($priceTmp)%3 !=0) // Using sizeof turned this into an endless loop as the the modulus by 3 will never be zero for 1
82 {
83    $tmp = "0".$priceTmp;  //here it throws an error
84    $priceTmp = $tmp;
85 }


You are entering an endless loop as the modulus by 3 of one (constant) will never be 0.
As indicated in my modification of your code snippet you need to use int strlen(string $string) instead.

Best,
— Manfred
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900