ONLY ECHO THE FIRST WORD OF A STRING - Mar 15th, 2012


I had a situation where I needed to strip all but the first word of a string and use that as part of a mailto:link but I
also wanted to use the entire string in the link text.

I found that I could echo a specific word from an array but I was starting with a multi-word text string.

So first I converted the string to an array with:



<?php $position = mytableRecord['myfield'] ?>
<?php $myArray = explode(" ", $position);?>



Then I echoed the first element (which has an index of [0]) in the array with:



<?php echo strtolower($myArray[0]);?>



Then I placed all that in my mailto: link



<a class="special" href="mailto:<?php $myArray = explode(" ", $position);?><?php echo
strtolower($myArray[0]);?>@my_web_site.org">E-MAIL THE <?php echo strtoupper($position); ?></a>









The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service