0

I need to explode <TD>, but in code (I need to extract the data from another website that is not mine). There is <TD> with many different attributes, so I can not just write

explode("<TD>",$tableA_data[1]));

And if I write it like

explode("<TD",$tableA_data[1]));

without > mark, it will put that mark in my result. I tried to remove that mark with

str_replace('>',"", $tableA_data);

but it does nothing with result.

CODE:

$tableA_data = explode('<table border="0" cellspacing="0" class="evidenceUpadcuDetailTable">',$result1);
$tableA_data = str_replace('ALIGN="center" nowrap="nowrap">',"", explode("<TD",$tableA_data[1]));
Misa Lazovic
  • 2,805
  • 10
  • 32
  • 38
Slouchy
  • 33
  • 7
  • Try regex. This may be a good starting point http://php.net/manual/en/function.preg-match.php – Nouphal.M Nov 21 '15 at 14:23
  • Nouphal how could i use preg match in explode, can you give me some code so I have something to start? Or example of what you mean. – Slouchy Nov 21 '15 at 14:41
  • @Nouphal.M Never ever ever ever use regex to parse HTML. It is [impossible](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – JvO Nov 21 '15 at 15:08
  • @JvO Yea I thought that, so that is the reason why I asked him that question. – Slouchy Nov 22 '15 at 17:49

2 Answers2

2

IMO the best option is using a simple HTML parser like Ganon, I used it in a small project and it works nicely and you could also grab any tag you want.

Mat
  • 2,156
  • 2
  • 16
  • 29
  • Yea it could be nice Idea, but I now have whole website based on eplode and getting content by curl, I will try that as last chance. But Thanks a lot anyway at least I have something that will work if I/We can not figure it out. – Slouchy Nov 21 '15 at 14:42
0

I solved it with substr($foo, 1). Which will basicly remove first character of string $foo. I thing it is not a best way how to do that, but in my case it worked. I will sign Mat´s answer as correct, because it will do work better i thing, thanks guys for help.

Slouchy
  • 33
  • 7