Jump to content

splitting a field


demojuan

Recommended Posts

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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>";
?>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.