demojuan Posted October 22, 2008 Share Posted October 22, 2008 I am working on a project where I want split up one field into two parts. I would like it to display the first four charecters in one xml group and the last three in the next xml group. Is there an easy way to do this? here is the string i would like to split in two "<phone>{$row['phone']}</phone>" . I am new to all this so please bare with me. Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/ Share on other sites More sharing options...
AjBaz100 Posted October 23, 2008 Share Posted October 23, 2008 $val = $row['phone']; echo '<phone>'.substr($val, 0, 4 ).'</phone>'; echo '<phone>'.substr($val, 4, strlen($val) ).'</phone>'; Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-672542 Share on other sites More sharing options...
demojuan Posted October 23, 2008 Author Share Posted October 23, 2008 That is exactly what I want to do but it did not work. Here is the full code that I am working with. <?php include 'mtcvbconfig.php'; $query = "SELECT first, last, title, depart, email, phone, ext, mobile, dob, hmAdd, hmAdd2, hmCity, hmState, hmZip,imageURL FROM employee WHERE first = 'Joshua'"; $result = mysql_query($query); echo "<team>"; while($row = mysql_fetch_assoc($result)) { echo "<person title=\"{$row['title']} \">" . "<firstName>{$row['first']} </firstName>" . "<lastName> {$row['last']} </lastName>" . "<department> {$row['depart']} </department>" . "<phone>{$row['phone']}</phone>" . "<email>{$row['email']} </email>" . "<extension>{$row['ext']}</extension>" . "<mobile>{$row['mobile']}</mobile>" . "<dob>{$row['dob']}</dob>" . "<hmAdd>{$row['hmAdd']}</hmAdd>" . "<hmAdd2>{$row['hmAdd2']}</hmAdd2>" . "<hmCity>{$row['hmCity']}</hmCity>" . "<hmState>{$row['hmState']}</hmState>" . "<hmZip>{$row['hmZip']}</hmZip>" . "<imageURL>{$row['imageURL']}</imageURL>" . "</person>" ; } echo "</team>"; ?> Thank you for your help Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-672822 Share on other sites More sharing options...
fenway Posted October 23, 2008 Share Posted October 23, 2008 I don't see the suggested code in your sample. Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-673236 Share on other sites More sharing options...
demojuan Posted October 24, 2008 Author Share Posted October 24, 2008 Sorry, here is it. <?php include 'mtcvbconfig.php'; $query = "SELECT first, last, title, depart, email, phone, ext, mobile, dob, hmAdd, hmAdd2, hmCity, hmState, hmZip,imageURL FROM employee WHERE first = 'Joshua'"; $result = mysql_query($query); $val = $row['phone']; while($row = mysql_fetch_assoc($result)) { echo "<person title=\"{$row['title']} \">" . "<firstName>{$row['first']} </firstName>" . "<lastName> {$row['last']} </lastName>" . "<department> {$row['depart']} </department>" ; //the two lines below are where I need help echo "<PrePhone>".substr($val, 0, 4 )."</PrePhone>"; echo "<ExtPhone>".substr($val, 4, strlen($val) )."</ExtPhone>"; echo "<email>{$row['email']} </email>" . "<extension>{$row['ext']}</extension>" . "<mobile>{$row['mobile']}</mobile>" . "<dob>{$row['dob']}</dob>" . "<hmAdd>{$row['hmAdd']}</hmAdd>" . "<hmAdd2>{$row['hmAdd2']}</hmAdd2>" . "<hmCity>{$row['hmCity']}</hmCity>" . "<hmState>{$row['hmState']}</hmState>" . "<hmZip>{$row['hmZip']}</hmZip>" . "<imageURL>{$row['imageURL']}</imageURL>" . "</person>" ; } echo "</team>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-673872 Share on other sites More sharing options...
fenway Posted October 27, 2008 Share Posted October 27, 2008 What does it do currently? Quote Link to comment https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-675941 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.