uau… (:
I knew a foreach should be of some use here… I was seeing that $part will be an array with 0, 1, 2 index, and or simpleXML iteration lines will also have 0,1,2 index as well… and I was like: “How can I connect those two?”…
Niicee…
I’m learning…
@AnthonySterling:
I do believe that addLine will be a method that will simplify this:
$xmlObj->command->create->children(self::OBJ_URI_CONTACT)->create->postalInfo->addr->street[1] = $part;
So that, instead of having a bunch of lines like this, we can simple have:
$address->fillLine($line);
If we need to add a city, then it will be:
$city->fillLine($line);
etc…
I do have several classes on this project… but I’m assuming that we can build even more, and work with them. And once we do that, we are actually embracing OOP. Right now, I’m on oop only perhaps. ehehe
I will try to remember this.
For now however, I will make use of a better code excerpts and, little by little, move on to better structures.
I will take ScallioXTX simplification for now.
Thank you both!!
UPDATE
Ahh… but @ScallioXTX if we use:
$parts=str_split($street, 50);
foreach($parts as $part)
{
$xmlObj->command->create->children(self::OBJ_URI_CONTACT)->create->postalInfo->addr->street[1] = $part;
}
We always have street[1] to be filled. And the thing is, for each part, put it on street[0], then on street[1], and lastly on street[2], maybe a for with an index?
Something like this perhaps?
//split only if $street is great then 50;
if(strlen($street) > 50)
{
$parts=str_split($street, 50);
for($i=0; $i<3;$i++)
{
$xmlObj->command->create->children(self::OBJ_URI_CONTACT)->create->postalInfo->addr->street[$i] = $parts[$i];
}
}
Wrong. What if the street if less then 50 chars long. Nothing happen…
hhmmm…
So this instead perhaps… ?
if(strlen($street) > 50)
{
$parts=str_split($street, 50);
for($i=0; $i<3;$i++)
{ $xmlObj->command->create->children(self::OBJ_URI_CONTACT)->create->postalInfo->addr->street[$i] = $parts[$i];
}
}
else
{
$xmlObj->command->create->children(self::OBJ_URI_CONTACT)->create->postalInfo->addr->street[0] = $street;
}