chaosxkitten Posted March 13, 2011 Share Posted March 13, 2011 So say I have the variable $p = 10 , and I wanted to use it in css, so I'd need "10%". I've tried echoing it various ways, but nothing reads through the source code. $p% ($p)% '$p'% .... I'm not sure how to type this up. used like this: echo "div { width: $p%; }"; Link to comment https://forums.phpfreaks.com/topic/230533-using-a-variable-as-a/ Share on other sites More sharing options...
cunoodle2 Posted March 13, 2011 Share Posted March 13, 2011 If you view source what you do you get? Also you ending the line after the "%;" Maybe try this... echo "div { width: ".$p."% }"; I know that the "%" is often use as the MOD math function. I'm wondering if that had something to do with it. Try out my code and let me know what happens. Link to comment https://forums.phpfreaks.com/topic/230533-using-a-variable-as-a/#findComment-1187076 Share on other sites More sharing options...
spaceman12 Posted March 13, 2011 Share Posted March 13, 2011 escape with backslash as $p\% Link to comment https://forums.phpfreaks.com/topic/230533-using-a-variable-as-a/#findComment-1187084 Share on other sites More sharing options...
chaosxkitten Posted March 13, 2011 Author Share Posted March 13, 2011 Neither seems to work. the source code just prints like this: div { position: absolute; top: 20px; height: 600px; width: ".$w."% } Link to comment https://forums.phpfreaks.com/topic/230533-using-a-variable-as-a/#findComment-1187111 Share on other sites More sharing options...
chaosxkitten Posted March 13, 2011 Author Share Posted March 13, 2011 the program accepts: $p% but not in single quotes ' ', I had to use " " Link to comment https://forums.phpfreaks.com/topic/230533-using-a-variable-as-a/#findComment-1187118 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.