Jump to content

Recommended Posts

hi

 

say i have this string:

 

{cms type="textarea" name="qdos_entertainment_plc_para_1" cols="75" rows="5" style="border: 1px solid #000000;padding: 5px;"}

 

I want to match this:

 

{cms HERE CAN HAVE ANYTHING IN ANY ORDER BUT MUST HAVE name="NAME_HERE"} ANYTHING HERE {/cms}

 

what would be the expression?

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/
Share on other sites

basically i need it to match {cms name="bla bla"}(.*){/cms}

 

the part with the name bit is essential but there could be more params before or after it which should just be ignored

 

so for example, this is not valid

 

{cms type="textarea" rows="10" cols="5"}CONTENT TO RETURN HERE{/cms}

 

But this is valid

 

{cms name="blb lfdnjk" type="textarea" rows="10" cols="5"}CONTENT TO RETURN HERE{/cms}

 

And this is valid

 

{cms type="textarea" rows="10" cols="5" name="bla bla"}CONTENT TO RETURN HERE{/cms}

 

and this is also valid

 

{cms name="bla bla"}CONTWENT{/cms}

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843015
Share on other sites

MrAdam that is almost there i think. Check my longer post above, basically it needs to find the tag with the name="whatever" and return whats between the {cms}...{/cms} bit

 

so say i have {cms name="test" type="bla bla"}CONTENT HERE{/cms}

 

I have a var like $name = 'test'

 

it needs to go through the content i have looking for the cms tag with the name="$name" and return whats between the beginning and end tags, but the name parameter is allowed to fall anywhere within the first tag before or after any other param

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843019
Share on other sites

The regular expressions is right, it's just modifying the function a little bit now to return the matches.

 

preg_match_all('/\{cms[^\}]*name="[^"]+"[^\}]*\}[^\{]+\{\/cms\}/', $str, $matches);

print_r($matches);

 

The $matches array will contain what you're after...

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843022
Share on other sites

but it doesnt!

 

if i have the tag as this:

 

{cms type="textarea" name="qdos_entertainment_plc_para_1" cols="75" rows="5" style="border: 1px solid #000000;padding: 5px;"}Chaired by Nick Thomas, the company he created in 1986 is now one of the largest, broad-based entertainment Groups in the UK. Focussed on family entertainment and traditional values, the Group has grown both organically and through a steady 'buy & build' strategy focusing on businesses that complement the original model, managed by a coherent holding company.{/cms}

 

the array only comes back with position 0 there are no other elements so all its doing is returning the entire string i pasted above. what i want to do is get the actual content between the tags and replace it with something else

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843024
Share on other sites

ok here is 1 more issue with this

 

the expression /\{cms[^\}]*name="[^"]+"[^\}]*\}(.*){\/cms\}/  seems to work, but if the content has a special charcter say an apostraphie, it seems to stop matching at the symbol and cuts the text off

 

so in this example text below it cuts off right after "'buy"

 

Chaired by Nick Thomas, the company he created in 1986 is now one of the largest, broad-based entertainment Groups in the UK. Focussed on family entertainment and traditional values, the Group has grown both organically and through a steady 'buy & build' strategy focusing on businesses that complement the original model, managed by a coherent holding company.

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843029
Share on other sites

it doesnt! it cuts the text off like this:

 

Chaired by Nick Thomas, the company he created in 1986 is now one of the largest, broad-based entertainment Groups in the UK. Focussed on family entertainment and traditional values, the Group has grown both organically and through a steady \'buy

 

unless thats the javascript doing that when i send the string to the ajax file

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843033
Share on other sites

another quick question... now i have the content from the middle and i have it replacing with preg_replace  how can i actually return everything thats between {cms params here} because i dont actually want to replace the {cms PARAMS}...{/cms} bits just whats between them

Link to comment
https://forums.phpfreaks.com/topic/159840-pattern-match/#findComment-843037
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.