0

Hello ,

im using the following code to Retrieve the DOM from URL all "A" tags and print their HREFs Now my output is contain "A" i dont want its my out is here http://trend.remal.com/parsing.php

i need to clear my out to be only the name after http://twitter.com/namehere

so output print list of "namehere"

    include('simple_html_dom.php');

 // Retrieve the DOM from a given URL
 $html = file_get_html('http://tweepar.com/sa/1/');
 $urls = array();

  foreach ( $html->find('a') as $e )
  {
  // If it's a twitter link
  if ( strpos($e->href, '://twitter.com/') !== false )
  {
    // and we don't have it in the array yet
    if ( ! in_array($urls, $e->href) )
    {
        // add it to our array
        $urls[] = $e->href;
    }
   }
   }

  echo implode('<br>', $urls);

echo $e->href . '<br>';
1
  • The parameters to in_array are backward. If you want to search $urls for an instance of $e->href, use in_array($e->href, $urls). That will fix the "Warning: in_array() expects parameter 2 to be array, string given" problem. Commented Sep 9, 2012 at 10:57

1 Answer 1

2

Instead of simply using $urls[] = $e->href, use a regex to match the username:

preg_match('~twitter.com/(.+)~', $e->href, $matches);
$urls[] = $matches[1];
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.