We help IT Professionals succeed at work.
Get Started

How do I fix this REGEX statement

rlb1
rlb1 asked
on
341 Views
Last Modified: 2012-05-10
Experts,

How do I fix this regex statement and pull out the desired data?

I am trying to ignore the cat_id        cat_id=([.*])     using the "  .* "  tag,  and only pull out the category name located where the   (.*?)  

Original String:
<a href="/categories.asp?cat_id=([.*])">(.*?)</a>


Original Result:
Audio Video Cables > Video Cables > HDMI Cables

Thanks for your help!!
//Original Code

<div id="product_header">
<a href="/categories.asp?cat_id=2000">Audio Video Cables</a> &gt; <a href="/categories.asp?cat_id=8820003">Video Cables</a> &gt; <a href="/categories.asp?cat_id=2030">HDMI Cables</a>
    </div>


My Attempt:
// Categories
preg_match_all('%<div id="product_header">
        <a href="/categories.asp?cat_id=([.*])">(.*?)</a> &gt; <a href="/categories.asp?cat_id=([.*])">(.*?)</a> &gt; <a href="/categories.asp?cat_id=([.*])">(.*?)</a>
    </div>%s',$data,$matches6,PREG_SET_ORDER);




$category=$matches6[0][1];
$subcat=$matches6[1][1];
$subsubcat=$matches6[2][1];


echo $category."<br />";
echo $subcat."<br />";
echo $subsubcat."<br />";

Open in new window

Comment
Watch Question
Web Application Programmer
Commented:
This problem has been solved!
Unlock 4 Answers and 10 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE