|
Posted by Koncept on 09/03/06 22:06
In article <4lvv78F3qicuU1@individual.net>, J.O. Aho <user@example.net>
wrote:
> kenoli wrote:
> > I often see syntax used in code snippets that is different than that
> > indicated in the php manual, at least in the main topic pages.
>
> How do you mean differs?
>
> like:
>
> $str1 = substr('abcdef', 1);
> $str2 = substr('abcdef', 0, 8);
>
> or?
>
>
> > Is there somewhere that I can find alternative syntax documented?
>
> The online manual gives you the valid syntaxes, or course they don't give all
> the examples how you can use functions.
>
>
> > I suspect that in some cases this may be a matter of the author using C
> > syntax that is slightly different than php syntax.
>
> PHP don't understand any other syntax than PHP.
>
>
> //Aho
He probably means:
[quote]
Alternative syntax for control structures
PHP offers an alternative syntax for some of its control structures;
namely, if, while, for, foreach, and switch. In each case, the basic
form of the alternate syntax is to change the opening brace to a colon
(:) and the closing brace to endif;, endwhile;, endfor;, endforeach;,
or endswitch;, respectively.
<?php if ($a == 5): ?>
A is equal to 5
<?php endif; ?>
In the above example, the HTML block "A is equal to 5" is nested within
an if statement written in the alternative syntax. The HTML block would
be displayed only if $a is equal to 5.
The alternative syntax applies to else and elseif as well. The
following is an if structure with elseif and else in the alternative
format:
<?php
if ($a == 5):
echo "a equals 5";
echo "...";
elseif ($a == 6):
echo "a equals 6";
echo "!!!";
else:
echo "a is neither 5 nor 6";
endif;
?>
[/quote]
--
Koncept <<
"The snake that cannot shed its skin perishes. So do the spirits who are
prevented from changing their opinions; they cease to be a spirit." -Nietzsche
Navigation:
[Reply to this message]
|