0

I am writing a script that will grab domain names from a webpage and print a list of ones that match certain criteria.

I have the data in an array but I can't seem to print it out in a friendly format although no matter what I try I cannot seem to extract what I need.

An example of my array is shown below:

Array
(
    [0] => Array
        (
            [0] => domain1.com.au
            [1] => domain2.com.au
            [2] => domain3.com.au
            [3] => domain4.com.au
            [4] => domain5.com.au
        )

)

Basically I just want to print each occurrence of *.com.au on a new line.

If someone to give me an example or suggestion it would be great.

1
  • also, please sanitize as Mihai sayd, before storing values Commented Aug 20, 2012 at 11:26

3 Answers 3

2
foreach ($array[0] as $domain){
    if(strstr($domain, '.com.au')){
        echo $domain."<br />";
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

This worked exactly how I wanted, I also like that you included sanitation as there is a possibility that stray data will find itself into the array.
2

The array you supplied should be in $array.

PHP_EOL inserts a newline if you look at the source. <br /> inserts a new line visually

foreach ($array[0] as $domain){
    echo $domain.'<br />'.PHP_EOL;
}

Comments

1

Try:

foreach( $arr[0] as $key => $value)
{
echo '<br/>'. $value;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.