1

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.

Veer Shrivastav
  • 5,434
  • 11
  • 53
  • 83
  • You also shouldn't set $_POST variables yourself like you are doing with $_POST['subject']. You should let the page do that itself and should be setting to a $_SESSION: http://stackoverflow.com/q/3235265/1744357 – rocket_boomerang_19 Nov 21 '13 at 06:00
  • Hi Veer, $_POST is used by Simple Machines Forum for numerous reasons. I was editing the Post.php file within this to manipulate how the subject line of a topic is displayed. – user3016121 Nov 21 '13 at 06:12

5 Answers5

0

Try this :

<span class="<?php echo $_POST['post_prefix'] ?>"><?php echo $_POST['post_prefix'] ?></span>
Mahmood Rehman
  • 4,303
  • 7
  • 39
  • 76
0

Try this code:

<span class="<?php echo $_POST['post_prefix']; ?>"><?php echo $_POST['post_prefix']; ?></span>
Jenz
  • 8,280
  • 7
  • 44
  • 77
0

Try this it will work exactly

 $_POST['subject'] =  '<span class='.$_POST['post_prefix'].'>'.$_POST['post_prefix'].'</span>' . '  ' . $_POST['subject'];
praveen
  • 286
  • 1
  • 8
0

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

Veer Shrivastav
  • 5,434
  • 11
  • 53
  • 83
0

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

echo "<span class='".$_POST['post_prefix']."'>".$_POST['post_prefix']."</span>";
Deepika Janiyani
  • 1,487
  • 9
  • 17