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

How to create a scaled down version of a custom NSView

cocoa custom-controls nsview

I have built a custom view component that displays a timeline of events. The component is built from several custom subclasses of NSView, each implementing specific visual aspects of the events in ...

Why is there huge performance hit in 2048x2048 versus 2047x2047 array multiplication?

c# arrays matrix-multiplication

I am making some matrix multiplication benchmarking, as previously mentioned in