Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I ran this code and it worked

<!DOCTYPE html>
<html>
<body>
<?php

$pizza  = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);

echo " $slices[0] <br> "  ; // slice1
echo $slices[1]; // slice2

?>
</body>
</html>


and when i run this code it worked the same way

<!DOCTYPE html>
<html>
<body>
<?php
// Check if the type of a variable is integer   

$pizza  = "slice1 slice2 slice3 slice4 slice5 slice6";

$x = substr_count($pizza , ' ')+1 ;

echo "$x <br>";

?>  
</body>
</html>



I don't know, maybe I made a string integer error, I thought I should define it from the beginning, so I searched this.

<?php
$x = 5985;
var_dump(is_int($x));

$x = 59.85;
var_dump(is_int($x));
?>




finally i wrote the following code but it gives me error

<!DOCTYPE html>
<html>
<body>

<?php

settype($x, "integer"); 
settype($y, "integer"); 



$pizza  = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);

$y =  substr_count($pizza , ' ')+1

for( $x = 0 ; $x <=  $y ; $x++ ) {



echo  $slices[$x] <br>  ;

}

?>

</body>
</html>



PHP Parse error: syntax error, unexpected 'for' (T_FOR) in /home/6TZO55/prog.php on line 17


What I have tried:

HTML
<!DOCTYPE html>
<html>
<body>

<?php

settype($x, "integer"); 
settype($y, "integer"); 



$pizza  = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);

$y =  substr_count($pizza , ' ')+1

for( $x = 0 ; $x <=  $y ; $x++ ) {



echo  $slices[$x] <br>  ;

}

?>

</body>
</html>
Posted
Updated 27-Jul-21 22:23pm

You are missing a semicolon:
PHP
$y =  substr_count($pizza , ' ')+1
                                  ^
                                  |
for( $x = 0 ; $x <=  $y ; $x++ ) {
Add it, and the error will go away.

Semicolons are important in PHP: every instruction must end with a semicolon (or a set of curly brackets in the case of flow control)
 
Share this answer
 
Comments
kaixian 6000 28-Jul-21 4:21am    
thank you 😁 . i use this site but i deleted a which put a new step solution newline . but i delete and this worked

i use this site

https://www.w3schools.com/php/phptryit.asp?filename=tryphp_regex_replace
<!DOCTYPE html>
<html>
<body>

<?php

settype($x, "integer"); 
settype($y, "integer"); 



$pizza  = "slice1 slice2 slice3 slice4 slice5 slice6";
$slices = explode(" ", $pizza);

$y =  substr_count($pizza , ' ')+1;

for( $x = 0 ; $x <=  $y ; $x++ ) {



echo  $slices[$x]  ;

}

?>

</body>
</html>
 
Share this answer
 

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



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