Scripts creates a menu list substituting the first word itself. This is the word that needs to be written in css, but I don’t know how to insert styles into php. tell me. Here is the code:

public function getProfileMenu($profile){ $menu = array( array( 'title' => ($profile['nickname']), 'url' => href_to($this->name, $profile['id']), 'url_mask' => href_to($this->name, $profile['id']), ) ); 

It is necessary to add styles to the nickname (that is, to insert html in php).

  • The code is inserted into the styles like this: <style> <? Php echo "insert"; ?> </ style> - nick_n_a

2 answers 2

In general, inserting CSS in PHP itself is a very bad practice. In the end, the global community is moving more and more towards the concept of sharing responsibility. Keep the logic in PHP, and leave the styles in cascading tables. The most common solution for a situation like yours is to wrap what is necessary in some lower-case element with a class and already in styles, to humanly describe what you want from it.

 array( 'title' => ('<span class="table-title">' . $profile['nickname'] . '</span>'), 'url' => href_to($this->name, $profile['id']), 'url_mask' => href_to($this->name, $profile['id']), ) 

Then in style.css, or as you call it:

 .table-title { //Ваши стили будут здесь } 

And keep the PHP code cleaner. And such questions will not arise. But if you really want to have css in the original HTML output, @Akainq said everything is right

    As an option through the style attribute:

      public function getProfileMenu($profile){ $menu = array( array( 'title' => ("<span style='color: red;'>".$profile['nickname']."</span>"), 'url' => href_to($this->name, $profile['id']), 'url_mask' => href_to($this->name, $profile['id']), ) );