Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.