vanvoquan Posted November 7, 2010 Share Posted November 7, 2010 Hi everyone, I have this code to help me split a long paragraph into sentences and make every new sentence into a new line. Now i want to insert a bullet point, or a arrow in font of every line. I try many different approaches, but it didn't work. Can anyone point me to the right direction. Thanks for your help. Vanvoquan. <table border="1" bordercolor="red"> <tr> <td> <p><?php echo stripslashes(str_replace('. ', '.<br />', $product_info['products_description'])); ?></p> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/ Share on other sites More sharing options...
Vitamin Posted November 7, 2010 Share Posted November 7, 2010 You could always use the HTML <ol> and <li> tags Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131326 Share on other sites More sharing options...
vanvoquan Posted November 7, 2010 Author Share Posted November 7, 2010 Thanks for reply Vitamin. I know we can use the <li></li> tag, but where to put it in this portion of this code. <table border="1" bordercolor="red"> <tr> <td> <p><?php echo stripslashes(str_replace('. ', '.<br />', $product_info['products_description'])); ?></p> </td> </tr> </table> I did try to put the <li></li> tag after the <br /> like this: <?php echo stripslashes(str_replace('. ', '.<br /><li></li>', $product_info['products_description'])); ?> It gave me the bullet point but in a new line by itself. I need it appear in the front of every sentences. Can anyone please help. Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131332 Share on other sites More sharing options...
Vitamin Posted November 7, 2010 Share Posted November 7, 2010 Try something like this. <table border="1" bordercolor="red"> <tr> <td> <ol> <li><?php echo stripslashes(str_replace('. ', '.<br />', $product_info['products_description'])); ?></li> </ol> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131336 Share on other sites More sharing options...
vanvoquan Posted November 7, 2010 Author Share Posted November 7, 2010 Thanks for reply Vitamin. It just gave me a "1." at the first line, that's it. Anyone know how to make this happen? Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131340 Share on other sites More sharing options...
joel24 Posted November 7, 2010 Share Posted November 7, 2010 you need to modify the CSS for the list (<li>) so that it displays bullets, default is numbered. list-style: circle; or list-style: image url(rarrara/img.jpg); Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131345 Share on other sites More sharing options...
revraz Posted November 7, 2010 Share Posted November 7, 2010 I think what you will have to do is create a loop for this if you want it at the start. Your current code starts replacing at the period, so you are already at the end of the sentance. Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131346 Share on other sites More sharing options...
vanvoquan Posted November 7, 2010 Author Share Posted November 7, 2010 Thanks for helping me out Joel24 and Revraz. I think Revraz point me out the right direction here. I'm really new to php, so Revraz, can you please show me how to create the loop ? I have no idea where to start. Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131350 Share on other sites More sharing options...
revraz Posted November 7, 2010 Share Posted November 7, 2010 How I would approach this is load each sentance into an array, then as you echo out each array element, you can use the HTML List to display it. Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131359 Share on other sites More sharing options...
litebearer Posted November 7, 2010 Share Posted November 7, 2010 Just an example... <?PHP /* replace the content for $MY_PARAGRAPH with the content you are using */ $my_paragraph = "Lorem ipsum his option regione explicari id, eum an ferri decore. Qui ex ridens graecis, debitis placerat eu mei. No est unum decore, ex elit prima eum. Et fabulas appetere patrioque est. Eu elitr labore luptatum sea, ne ullum indoctum comprehensam nam, usu dicta instructior id. Definiebas philosophia ei sed, mei et putent cetero patrioque. Id quo assum dissentiunt. Usu ipsum consul oblique et. Cu quo malis debitis sapientem, et accusam detracto pro, eu aliquid quaerendum est. Nam eu enim gloriatur. Id autem blandit praesent vix. Brute graeco ei eos. An eos sumo porro putant, sit in unum blandit suavitate. Mel ex propriae oporteat comprehensam. Mei consul mediocrem neglegentur an, ea adhuc erant contentiones sit, sea et ferri malis. Vim minim scripserit temporibus ut, an cum harum detraxit."; /* this is the code for displaying a bullet followed by 2 spaces */ $b = "• "; /* create an array from your paragraphm using the period as the delimiter */ $my_array = explode(".", $my_paragraph); /* count the number of elements in your array */ $count = count($my_array); /* check to see if the last element is empty - if it is then remove it and decrease the element count by 1 */ $last_element = $count - 1; if(trim($my_array[$last_element])<1) { $junk = array_pop($my_array); $count = $count - 1; } /* display the results - for example purposes, we as lso showing the original paragraph */ echo "The paragraph...<p>"; echo $my_paragraph; echo "<hr>"; echo "The paragraph sentences, listed with leading bullets and spaces...<p>"; $i = 0; while($i<$count) { echo $b . trim($my_array[$i]) . ".<br>"; $i ++; } ?> http://nstoia.com/test/bullet.php Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131390 Share on other sites More sharing options...
vanvoquan Posted November 7, 2010 Author Share Posted November 7, 2010 Thanks Litebearer. It work like a charmp. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/217994-how-to-insert-a-bullet-point-please-help/#findComment-1131446 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.