2

i have this content on an external URL:

{"sEcho":null,"iTotalRecords":97,"iTotalDisplayRecords":97,"aaData":[["<a href='#' onClick='return numberPortingShow(\"10621\");'><img border='0' class='tableImage' src='/ControlPanel/Images/Icon/application_view_icons.png' alt='View Porting Details' title='View Porting Details'/></a> <a href='#' onClick='return numberPortingShow(\"10621\");'>0123456789</a>","<a href='/ViewAccount?account_no=20726' target='_blank'>20726</a>","Single Analogue","19/05/2015 14:30","29/05/2015 17:00","Complete”],["<a href='#' onClick='return numberPortingShow(\"10621\");'><img border='0' class='tableImage' src='/ControlPanel/Images/Icon/application_view_icons.png' alt='View Porting Details' title='View Porting Details'/></a> <a href='#' onClick='return numberPortingShow(\"10621\");'>0987654321</a>","<a href='/ViewAccount?account_no=20726' target='_blank'>20726</a>","Single Analogue","19/05/2015 14:30","29/05/2015 17:00","Complete"]]}

how can i loop through this data in PHP, while reading it from an external URL

1
  • This looks like json encoded data. Use json_decode(). And have fun. Actually the headers you received from that url should have told you so. Commented Jul 19, 2015 at 18:44

2 Answers 2

1

Your data looks like JSON string so use json_decode() and iterate over it.

$data = '{"sEcho":null,"iTotalRecords":97,"iTotalDisplayRecords":97,"aaData":[["<a href='#' onClick='return numberPortingShow(\"10621\");'><img border='0' class='tableImage' src='/ControlPanel/Images/Icon/application_view_icons.png' alt='View Porting Details' title='View Porting Details'/></a> <a href='#' onClick='return numberPortingShow(\"10621\");'>0123456789</a>","<a href='/ViewAccount?account_no=20726' target='_blank'>20726</a>","Single Analogue","19/05/2015 14:30","29/05/2015 17:00","Complete"],["<a href='#' onClick='return numberPortingShow(\"10621\");'><img border='0' class='tableImage' src='/ControlPanel/Images/Icon/application_view_icons.png' alt='View Porting Details' title='View Porting Details'/></a> <a href='#' onClick='return numberPortingShow(\"10621\");'>0987654321</a>","<a href='/ViewAccount?account_no=20726' target='_blank'>20726</a>","Single Analogue","19/05/2015 14:30","29/05/2015 17:00","Complete"]]}';
$dataArray = json_decode($data, true);
foreach ($dataArray as $key => $value) {
    var_dump($key);
    var_dump($value);
}
Sign up to request clarification or add additional context in comments.

4 Comments

in the $data variable, its commenting out some of it because of the # and its having some issues due to the ' and " - whats the best way to help this?
@charlie I didn't notice, sorry. How you retrieve your data?
well, its coming from an external URL
@charlie OK, and how you read it in your code? Are you using cURL or file_get_contents()?
0

I think you need php curl, followed by json_decode.

References:

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.