unemployment Posted May 5, 2011 Share Posted May 5, 2011 How can I add a period at the end of the sentence with this.. if($i > $max) break; if($i == $max || ($i == count($information) && $i > 1)) echo ' and '; else { if($i > 1) echo ', '; } if ($info[0] == 'credentials') { echo "credentials"; } if ($info[0] == 'specialties') { echo "specialties"; } if ($info[0] == 'stageofdevelopment') { echo "stage of development to {$info[1]}"; } $i++; Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/ Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 not sure i can work out where the sentences start and end but maybe passing the output to a concatenating string and then add it to the final string? Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210905 Share on other sites More sharing options...
cssfreakie Posted May 5, 2011 Share Posted May 5, 2011 maybe instead of directly echoing the value, assign the value to a string with .= like: $string = 'monkeys '; $string .= 'eat '; $string .= 'banana\'s'; $string .= '.'; echo $string; // outputs monkeys eat banana's. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210906 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 not sure i can work out where the sentences start and end but maybe passing the output to a concatenating string and then add it to the final string? The sentence would say something like.. you have updated you specialties, credentials and stage of development. I need to add in the period at the end. Keep in mind that the sentence could also say something like. The sentence would say something like.. you have updated you specialties and credentials. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210907 Share on other sites More sharing options...
cssfreakie Posted May 5, 2011 Share Posted May 5, 2011 did you try the given example?? Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210908 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 maybe instead of directly echoing the value, assign the value to a string with .= like: $string = 'monkeys '; $string .= 'eat '; $string .= 'banana\s'; $string .= '.'; echo $string; // outputs monkeys eat banana's. Even if I assign it to a string it will eventually be echoed anyway. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210909 Share on other sites More sharing options...
cssfreakie Posted May 5, 2011 Share Posted May 5, 2011 Even if I assign it to a string it will eventually be echoed anyway. indeed, but this way you can alter the output.... which is what you wanted (a string with a dot at the end) Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210910 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 Even if I assign it to a string it will eventually be echoed anyway. indeed, but this way you can alter the output.... which is what you wanted (a string with a dot at the end) I can't see that working with what I have. If it does please teach me. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210914 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 if you dont want to try the string method why not just echo out a period after the loop ends the sentence? or is it looping several sentences in a row? Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210916 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 if you dont want to try the string method why not just echo out a period after the loop ends the sentence? or is it looping several sentences in a row? I would do that but it puts a space between the last word and the period like this . Which is pretty annoying. Any ideas on how to remove the space that an echo adds in? Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210935 Share on other sites More sharing options...
spiderwell Posted May 5, 2011 Share Posted May 5, 2011 here comes the irony, pass it to a string and use rtrim() (trims space from the right) you could probably do that directly into the echo statement too though, I just want you to use strings Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210939 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 here comes the irony, pass it to a string and use rtrim() (trims space from the right) you could probably do that directly into the echo statement too though, I just want you to use strings Turning the text based words into a string is no big deal, but how would I turn this into a string? if (($info[0] == 'companywebsite') || ($info[0] == 'personalwebsite')) { ?> website to <a href="<?php $info[1]; ?>"><?php echo substr($info[1], 7);?></a> <?php } By the way, putting rtrim() around the echo didn't work for me. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210976 Share on other sites More sharing options...
dragon_sa Posted May 5, 2011 Share Posted May 5, 2011 if (($info[0] == 'companywebsite') || ($info[0] == 'personalwebsite')) { $info1=$info[1]; $web="website to <a href='$info1'>"; $web.=substr($info1, 7); $web.="</a>" echo $web; } Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210980 Share on other sites More sharing options...
unemployment Posted May 5, 2011 Author Share Posted May 5, 2011 Thank you for the explanation and yes, strings solved my problem. Link to comment https://forums.phpfreaks.com/topic/235601-add-period-to-end-of-sentence/#findComment-1210987 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.