1

I am trying to use preg_replace function to parse this table in a Html page :

Tuition.    $13,140   $13,167    $13,167    
Books       $996      $1,176     $1,176

Because of table tags I got "Unknown modifier 't' " error and I changed '/ /' with '~ ~'.

Still I have problem, the function is not changing the text. I think the problem with '$' dollars sign in the text, how can I skip it? I tried to do but I couldn't.

Here is my code :

$price = $html->find('div[id=divctl00_cphCollegeNavBody_ucInstitutionMain_ctl00] table[class=tabular]');

        $price1=$price[0];
        $show=$price1;

        $ch="~".$show->children(1)->children(0)->children(1)."~";
        $show=preg_replace($ch,' ',$show, 1);

Thanks

6
  • 2
    Using preg_quote will escape the pattern so the preg_replace works, but I'm not sure what you're actually trying to do with the table? Commented Mar 20, 2012 at 21:03
  • Yes preg_quote also skips '< >' character and it breaks my table, I want to keep HTML tags, I just want to skip dollar sign. I am trying to transfer data from one website to another. Commented Mar 20, 2012 at 21:04
  • Show us what is in $ch Commented Mar 20, 2012 at 21:04
  • $ch will be in a for loop and each time it will keep data on the table. When you made $ch="Tuition and fees" there is no problem but when you out $ch=$13,140 it is not working Commented Mar 20, 2012 at 21:07
  • I just mentioned dollar sign but the problem may be with comma as well, or another reason. I am not good at regex I just started learning and I need to fix this for my project. Commented Mar 20, 2012 at 21:16

1 Answer 1

2

try this : $show=preg_replace(str_replace('$','\$',$ch),' ',$show, 1); If you can't use preg_quote and have multiple escape ( in this case $ is your problem), you could put your special character in an array and filter from it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.