user11845248
user11845248

Reputation: 141

html inside php inside html parsing issue

I'm having this problem

Uncaught SyntaxError: Unexpected end of input

in this line

<?php ... foreach($res as $row) {echo '<input onclick="selectall('.$j.',"flow'.$row['uid'].'","hi'.$row['uid'].'")" type="submit" class="btn btn-primary btn-user btn-block" value="Update" />';} ?>

Output of that line

<input onclick="selectall(5,"flow9C2748C40A24","hi9C2748C40A24")" type="submit" class="btn btn-primary btn-user btn-block" value="Update" />

The problem is here i think

,"flow'.$row['uid'].'","hi'.$row['uid'].'"

because when i remove it, the problem disappear

Appreciate any help !

Upvotes: 0

Views: 32

Answers (1)

Professor Abronsius
Professor Abronsius

Reputation: 33813

There are a couple of functions which should possibly help when it comes to formatting strings - namely printf and sprintf (others in this family also exist) - and these allow you to specify placeholders in the string which are substituted with the arguments provided. Using these helps simplify how the strings are escaped

printf(
    '<input type="submit" onclick="selectall( \'%1$s\', \'flow%2$s\', \'hi%2$s\' )" value="Update" class="btn btn-primary btn-user btn-block" />',
    $j,
    $row['uid']
);

Upvotes: 1

Related Questions