I've this regex expression for the preg_match_all()
that matches correctly on regex101.com but not on my code.
The html element I'm trying to parse looks like this:
<a class="profile-link" href="CompanyProfile.aspx?PID=4813&country=211&practicearea=0&pagenum=" title="1-844-Iran-Law">Amin Alemohammad</a>
Which is found int the whole html curl result. Each block has the following eg.:
<li style="opacity: 1;">
<a class="profile-link" href="CompanyProfile.aspx?PID=4813&country=211&practicearea=0&pagenum=" title="1-844-Iran-Law">Amin Alemohammad</a>
<!--<a class="profile-link" href="javascript:void(0)" title="1-844-Iran-Law">Amin Alemohammad</a>-->
<img src="/Images/Uploaded/Photos/4813_1844IranLaw.png" style="max-width:140px; max-height:140px">
<div class="results-profile">
<h2>Amin Alemohammad</h2>
<p><strong>Firm:</strong> 1-844-Iran-Law <br> <strong>Country:</strong> USA</p>
<p class="blue"><strong>Practice Area:</strong> Iranian Desk</p>
<ul>
<li class="tel-icon" style="opacity: 1;">Tel: +1-202-465-8692</li>
<li class="fax-icon" style="opacity: 1;">Fax: +1-202-776-0136</li>
<li class="email-icon">Email: <a style="position:relative; z-index:9999;" href="mailto:amin@1844iranlaw.com">amin@1844iranlaw.com</a></li>
</ul>
</div><!-- results profile -->
<img class="practice-logo" src="/Images/Uploaded/Logos/4813_1844IranLaw.png" style="max-width:185px; max-height:70px;">
<a class="results-btn contact-btn" href="CompanyProfile.aspx?PID=4813&country=211&practicearea=0&pagenum=" title="View Full Profile">VIEW FULL PROFILE</a>
<!--<a class="results-btn contact-btn" href="CompanyProfile.aspx?PID=4813&country=211&practicearea=0&pagenum=" title="1-844-Iran-Law">CONTACT</a>-->
<a class="results-btn website-btn" href="http://www.1844iranlaw.com" title="www.1844iranlaw.com">VIEW WEBSITE</a>
</li>
</li>
The regex result
Group 1. 54-58 `4813` // company profile
Group 2. 71-74 `211` // country id
Group 3. 92-93 `0` // practice area
Group 5. 115-129 `1-844-Iran-Law` // company name
Group 6. 131-147 `Amin Alemohammad` // Person's name
What I have is:
preg_match_all('/<a class="profile-link" href="CompanyProfile\.aspx\?PID=(.*?)&country=([0-9]{1,}?)&practicearea=([0-9]{1,10}?)&pagenum=\?" title="(.*?)">(.*?)<\/a>/', $result, $match, PREG_PATTERN_ORDER);
dd($match);
which returns
array:6 [▼
0 => []
1 => []
2 => []
3 => []
4 => []
5 => []
]
The number of matches are correct -> 5 matches in the string pattern but what I can't figure out is why it's returning empty values.
Thanks for any help in advance as I've tried so many approaches but for not the correct one or seeing what am I missing.