# Help with php arrays in function

**URL:** <https://forum.kirupa.com/t/help-with-php-arrays-in-function/184511>\
**Category:** Uncategorized\
**Created:** [April 5, 2006, 4:58pm UTC](https://forum.kirupa.com/t/help-with-php-arrays-in-function/184511 "2006-04-05T16:58:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeepkiran](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@sandeepkiran](https://forum.kirupa.com/u/sandeepkiran)\
**Post date:** [April 5, 2006, 4:58pm UTC](https://forum.kirupa.com/t/help-with-php-arrays-in-function/184511/1 "2006-04-05T16:58:55Z")

</div>

Hello below is the code iam using. It works fine and outputs the content of an xml tag. but i want to store this in an array. Please help me do this.

\<?php  
$new =array();  
$file ="\<?xml version=‘1.0’ encoding=‘utf-8’?\>  
\<Sites\>  
\<Site\>  
\<URL\>[www.SitePoint.com](http://www.SitePoint.com)\</URL\>  
\<Title\>SitePoint Hub\</Title\>  
\</Site\>  
\<Site\>  
\<URL\>[www.WebmasterBase.com](http://www.WebmasterBase.com)\</URL\>  
\<Title\>Build your Site\</Title\>  
\</Site\>  
\</Sites\>";  
function contents($parser, $data){  
echo “\<p\>”.$data."\</p\>";  
$new.=$data;

}  
function startTag($parser, $data){

# echo “\<b\>”.$data."\<br\>";

echo “\<b\>”;  
}  
function endTag($parser, $data){

# echo “\</b\>\<br /\>”.$data."\<br\>";

```
echo "&lt;b&gt;";

```

}  
$xml\_parser = xml\_parser\_create();  
xml\_set\_element\_handler($xml\_parser, “startTag”, “endTag”);  
xml\_set\_character\_data\_handler($xml\_parser, “contents”);

$data = $file;  
if(!(xml\_parse($xml\_parser, $data))){  
die("Error on line " . xml\_get\_current\_line\_number($xml\_parser));  
}  
xml\_parser\_free($xml\_parser);  
?\>

here is the oputput i receive

\*\*

\*\*[www.SitePoint.com](http://www.SitePoint.com)  
\*\*

\*\*SitePoint Hub  
\*\*

\*\*

\*\*

\*\*[www.WebmasterBase.com](http://www.WebmasterBase.com)  
\*\*

\*\*Build your Site  
\*\*

\*\*

\*\*Array \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

Any help

Thanks,  
Sandeep. B

---

<div class="post-metadata">

**Author:** ![sandeepkiran](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@sandeepkiran](https://forum.kirupa.com/u/sandeepkiran)\
**Post date:** [April 5, 2006, 5:02pm UTC](https://forum.kirupa.com/t/help-with-php-arrays-in-function/184511/2 "2006-04-05T17:02:37Z")

</div>

if i declare the variable inside the function it accepts it as a single string. But not as an array. I tried explode but had no success. So any help
