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
https://forums.phpfreaks.com/topic/129673-splitting-a-field/
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
https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-672822
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
https://forums.phpfreaks.com/topic/129673-splitting-a-field/#findComment-673872
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.