0

For some reason I'm getting the word 'array' as an output when I try to do a foreach to echo out the values in an array (there are 2 values). These show fine if I use print_r in the array so I know they are there. I've also tried using as list but that only shows the first value and nothing after it.

It's getting late so it might be something pretty silly! Thanks in advance

<?php

$crawl_url = "./emails.php";

function get_email($url) {
    $input = @file_get_contents($url);
    $regexp = '/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i';
    preg_match_all($regexp, $input, $matches);

    if (empty($input)) {
        echo "No email addresses found";

    }   
    else {
        foreach($matches as $matches_values) {
            print $matches_values;
        }
    }
}

get_email($crawl_url);
echo '<br /> function complete';
?>

1 Answer 1

3

I think you're missing the 0 index on $matches.

Try this :

foreach($matches[0] as $matches_values) {
    print $matches_values;
}
Sign up to request clarification or add additional context in comments.

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.