New PHPer (or not even) with borrowed code not working

Hello,

I have a snippet of PHP code that should create an array of form radio buttons and then use the selection to generate a server hostname/URL but even though I know the code works on some php instances, it doesn’t seem to be working on mine. I was wondering if I have the syntax wrong somehow and that maybe my instance is less forgiving?? Any help appreciated…

[php]<? for($x = 0; $x <= 7; $x++) {
echo “<input id=“radiogroup” . $x .”" class=“element radio2” name=“smtpServer” type=“radio” value=“server” . $x . “.domain.com” />" .$x. "   ";
}
?>[/php]

It should look like the attachment but instead just shows as:

  • " .$x. " "; } ?>

EDIT: Solved my own issue here, forgot to declare it php at the start!


radio_array.PNG

I’m in the process of writing a trivia game written in PHP, JQuery and Ajax and I just so happen to have a radio button. I show you the code for I think it will help you out to make it easier in the future with writing HTML inside of PHP.

[php]echo ‘<input class="id_’ . $x . ’ id_num’ . $y . ‘" type=“radio” id="answer’ . $num . ‘“name=“correct” value=”’ . $y . ‘">’ . “\n”;
[/php]

When I writing HTML inside of PHP I use single quotation (’) marks instead of double quotation (") marks for I find it easier to read than having to do " all the time and you can use double " for proper HTML syntax without having to do " all the time, plus I tend to have less mistakes and/or find them faster.

BTW I have done that with <?php and the first time is usually the roughest for it wants to make you want to pull your hair out. :smiley:

Allow me to learn you up something. Your reasoning doesn’t hold up about having to escape.

Why the crazy class name or is it a type o? What you have would give you something like class=“id_5id_num2”

OP, You should be using HTML5. It has been officially released for almost two years now.

[php] <?= "\n" ?>[/php]

But why echo html at all…? I see no advantages over echoing php variables inside html. And in your output layer of your application (could just be the bottom of your php file) html should be the default language as that’s what you have most of

I fully agree. I am sure you have seen several of my posts ranting about not echoing html. I only used the code from the post to show you don’t have to do all that escaping.

[php] @foreach($day[‘events’] as $event)

{{ $event[‘alertType’] }} - {{ $event[‘alertSubj’] }}



@if(isset($event[‘alertDisplayTime’]))
{{ CALENDAR_TIME }} {{ $event[‘alertDisplayTime’] }}
@endif
{{ CALENDAR_INFORMATION }} {{ $event[‘alertText’] }}

@endforeach[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service