Victory Posted July 11, 2013 Share Posted July 11, 2013 Hi guys, It's a simple question really (just getting used to php - actionscript 3.0 developer!) but I need to know how I can pass a CSS class into the arguments in a PHP function, then have it apply that style to text in html. What I have so far is: <?php function addText($text,$class) { ?> <div class= $class > <p><?php echo $text ?></p> </div> <?php } ?> But it doesn't work, the <div class = $class > should be different I think. Anybody got a solution? Link to comment https://forums.phpfreaks.com/topic/280070-how-can-i-pass-a-css-class-style-into-a-php-functions-parameter/ Share on other sites More sharing options...
doddsey_65 Posted July 11, 2013 Share Posted July 11, 2013 <div class= $class > <p><?php echo $text ?></p> </div> Just as you have echoed the $text variable you will need to do so for the $class variable <div class="<?php echo $class; ?>"> <p><?php echo $text; ?></p> </div> Also needs to be wrapped in double quotes ( or single if you prefer ) for valid HTML syntax Link to comment https://forums.phpfreaks.com/topic/280070-how-can-i-pass-a-css-class-style-into-a-php-functions-parameter/#findComment-1440326 Share on other sites More sharing options...
Victory Posted July 11, 2013 Author Share Posted July 11, 2013 Thank you Doddsey! I thought the echo statement was like return... interesting in the way it works differently. Link to comment https://forums.phpfreaks.com/topic/280070-how-can-i-pass-a-css-class-style-into-a-php-functions-parameter/#findComment-1440329 Share on other sites More sharing options...
Irate Posted July 11, 2013 Share Posted July 11, 2013 echo is a language construct unlike return (that's a statement) and is not terminating in the way return is (return is mostly used with functions to return a value which becomes the value of the function). Link to comment https://forums.phpfreaks.com/topic/280070-how-can-i-pass-a-css-class-style-into-a-php-functions-parameter/#findComment-1440370 Share on other sites More sharing options...
Victory Posted July 12, 2013 Author Share Posted July 12, 2013 echo is a language construct unlike return (that's a statement) and is not terminating in the way return is (return is mostly used with functions to return a value which becomes the value of the function). Yeah, I originally thought that echo would end the function immediately like return does. I use return all the time in AS3, but I had never encountered echo before. I'm using this with Thematic in WordPress, I'm using this function to add text to the page with filter hooks - just wondering, does anybody know the best way of getting the text to format to a specific section on the page? Like I use the following: add_filter('thematic_abovecomments',addText("Add comments here.","default-header")); But the text appears at the top of the page instead of formatting with the comments section. I guess I'm not using the filter hooks correctly, I can't figure it out... Link to comment https://forums.phpfreaks.com/topic/280070-how-can-i-pass-a-css-class-style-into-a-php-functions-parameter/#findComment-1440465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.