Jump to content

variable in regex


newb

Recommended Posts

I don't think the problem is your variable - I think it is just the regex expression in general. But, I would suggest:

1) Testing the regex with a hard coded value first to ensure it is working properly, THEN introduce the variable

2) creating the expression as a string variable outside of the actual preg_match. then you can echo the expression to the page for debugging purposes.

 

Without seeing what you are using for the $type there's no way to really know what the problem is. Although I do see some potential problems.

 

1. You use this right after the opening A tag "(.*)". That is a 'greedy' match, so it will likely match more characters than you want since the parser doesn't know when to end. you should probably use the question mark as you do in the previous usage

 

2. You then follow that by a space. Don't know if that is intentional or not.

2.

Link to comment
https://forums.phpfreaks.com/topic/197585-variable-in-regex/#findComment-1036991
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.