Search code examples
phpsimple-html-dom

extract partial text with innertext using Simple HTML dom parser


i am scraping an address from a span, the format of address is house_no address
landmark
city

i want to extract house number,landmark & city and store them in separate variable

example of address:

123, cool area <br> famous hospital<br>city

my code sould extract & store values like:

$variable1="123, cool area"
$variable2="famous hospital"
$variable3="city"

Solution

  • You could simply split the text along the <br> tags using

    $parts = explode("<br>", $fullAddress);
    

    You may then be better off to trim the results to remove excess spaces...

    $parts = array_map('trim', $parts);