dude32 Posted February 18, 2007 Share Posted February 18, 2007 I'm a beginner to PHP and I am trying to write a PHP script that takes a text string, bolds and/or underlines the text string, and outputs the altered string to the monitor and allow me to select the alteration of the string I desire. I have tried repeatedly and I think my code is just garbage so if somebody could post me an example of this it would be of great help. Thank you Link to comment https://forums.phpfreaks.com/topic/38993-solved-help-me-please-bolding-and-underlineing-text/ Share on other sites More sharing options...
jwk811 Posted February 18, 2007 Share Posted February 18, 2007 what? well to bold or underline you use <b> or <u> tags but i dont understand exactly what your trying to do Link to comment https://forums.phpfreaks.com/topic/38993-solved-help-me-please-bolding-and-underlineing-text/#findComment-187708 Share on other sites More sharing options...
JasonLewis Posted February 18, 2007 Share Posted February 18, 2007 PHP dosent do stuff like that, thats all HTML. PHP can help do that though. Link to comment https://forums.phpfreaks.com/topic/38993-solved-help-me-please-bolding-and-underlineing-text/#findComment-187716 Share on other sites More sharing options...
superuser2 Posted February 18, 2007 Share Posted February 18, 2007 We can, to put a string in a tag, prepend and append text to it. Like so: <?php $string = 'This will be bold'; $boldstring = "<b>$string</b>"; If you were to echo $boldstring you would get the text in bold. Now let's say you want to make a script to do this (I'm not sure why you are trying to do this, but at first guess you're building some kind of bbcode system) that would take input and then output. Let's say we'll do bold, underline, and italics. <?php if($_POST) //If form was submitted { $a = $_POST['a']; //This will be the 'action' variable that tells us what we need to do. $s = $_POST['s']; //This will be the string variable that holds the string we will manipulate. if(!$s) { $s = '<i>(no data)</i>'; } switch($a) //Make a switch to handle what action we get { case "b": echo "<b>$s</b>"; break; case "i": echo "<i>$s</i>"; break; case "u": echo "<u>$s</u>"; break; default: die("Invalid selection."); break; } echo "<br /><br />"; } ?> <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'> <select name='a'> <option value='b'><b>Bold</b></option> <option value='i'><i>Italics</i></options> <option value='u'><u>Underline</u></options> </select> <br /> <input type='text' name='s'> <br /> <input type='submit' value='Submit'> </form> That is tested and it should work. I am curious what you are trying to accomplish by this? Link to comment https://forums.phpfreaks.com/topic/38993-solved-help-me-please-bolding-and-underlineing-text/#findComment-187718 Share on other sites More sharing options...
dude32 Posted February 18, 2007 Author Share Posted February 18, 2007 Thank you very much! Link to comment https://forums.phpfreaks.com/topic/38993-solved-help-me-please-bolding-and-underlineing-text/#findComment-187734 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.