dynamic span class within a php file.

not really a php guy, but have a question. I'm wanting to take the following statement

    $_POST['subject'] =  $_POST['post_prefix'] . '  ' . $_POST['subject'];

I would like the

$_POST['post_prefix']

part to be within a span class so I can add some css styling to it.

So it ends up as something like

<span class="$_POST['post_prefix']">$_POST['post_prefix']</span>

I tried a few methods on here via search, but phpstorm keeps giving me errors all over the place about semicolons. So thought I'd ask the pros to save my sanity.

If there's a better way of doing this, then that would also be helpful.

Cheers.

Answers


Yes, that will give you errors, for sure, actually, $_POST['variable_name'] means something to PHP but not to HTML.

PHP creates a HTML page using its own variable. here $_POST['variable_name'] is a PHP variable so you need to print that variable in HTML

So, use this,

<span class="<?php echo $_POST['post_prefix'] ?>"><?php echo $_POST['post_prefix'] ?></span>

Here you are printing the PHP variable to make a mock HTML


Try this :

<span class="<?php echo $_POST['post_prefix'] ?>"><?php echo $_POST['post_prefix'] ?></span>

Try this code:

<span class="<?php echo $_POST['post_prefix']; ?>"><?php echo $_POST['post_prefix']; ?></span>

If it is a PHP file, with no HTML flowing around, try

echo "<span class='".$_POST['post_prefix']."'>".$_POST['post_prefix']."</span>";

Try this it will work exactly

 $_POST['subject'] =  '<span class='.$_POST['post_prefix'].'>'.$_POST['post_prefix'].'</span>' . '  ' . $_POST['subject'];

Need Your Help

Send a short signal to the audio jack of fixed frequency

c# audio windows-phone-8

I want to send a short signal with a fixed frequency of 15 000 HZ to the audio jack. That will be feasible on the Windows Phone 8 platform?

Worst case time complexity

complexity-theory analysis

i have an algorithm that searches into a directory and search for all the text files in that directory and any sub-directory. Assuming i do not know how many sub-directories and sub-sub directories...