Saturday, 17 March 2018

PHP parse HTML tags

Fast way:


Look for the index position of tag1 then look for the index position of /tag1. Then cut the string between those two indexes. Look up strpos and substr on php.net
Also this might not work if your string is too long.


$pos1 = strpos($bigString, '');
$pos2 = strpos($bigString, '
');
$resultingString = substr($bigString, -$pos1, $pos2);

You might have to add and/or substract some units from $pos1 and $pos2 to get the $resultingString right.
(if you don't have comments with tag1 inside of them sigh)


The right way:


Look up html parsers

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...