Jump to content

Forward Slash & New Line Issue, Urgent Pls.


buzzdeep

Recommended Posts

Hi PHP Experts...I'm new to regex expressions and facing a problem.

 

$pattern = "/\[amp (.*?)\](.*?)\[\/amp\]/";

 

This is suppose to look for tags [amp showbox=true|otheroptions=false] some text [/amp]

 

Now this word fine as long as I use the following text in the fronted:

 

[amp showbox=true|otheroptions=false]Click here to download[/amp]

 

But it breaks when I use any of the following:

 

[amp showbox=true|otheroptions=false]<a href=http://someurl.com>Click here</a> to download[/amp]

 

Possibly because of closing </a> as it has a forward slash.

 

[amp showbox=true|otheroptions=false]
Click here to download
[/amp]

 

Possibly because of new line returns.

 

[amp showbox=true|otheroptions=false]<h3>Click here to download</h3>[/amp]

 

Possibly because of closing </h3> as it has a forward slash.

 

Could someone please help modify the regex expression to take care of all the three situations?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/250122-forward-slash-new-line-issue-urgent-pls/
Share on other sites

    $pattern = '%\[amp (.*?)\](.*?)\[\/amp\]%s';
    preg_match_all($pattern, $content, $matches);

    for ($loop1 = 0; $loop1 < sizeof($matches[1]); $loop1++)
    {
        $protected_content = $matches[2][$loop1];
        $fields = explode("|", $matches[1][$loop1]);
        for ($loop2 = 0; $loop2 < sizeof($fields); $loop2++){
            $colums = explode("=", $fields[$loop2]);
            
            for ($loop3 = 0; $loop3 < sizeof($colums); $loop3++){
                
                switch($colums[$loop3]) {
                
                    case "error":
                        $error = trim($colums[$loop3+1]);
                    break;

                    case "pid":
                        $pid = trim($colums[$loop3+1]);
                    break;

                    case "showbox":
                        $showbox = trim($colums[$loop3+1]);
                    break;
                

                    default:
                    break;
                }   
            }
        }

 

If I use the reg expression you gave me then doesn't enter in the for loop at all. I use this content in the front end which is passed to the function that parses using regex code above.

 

[amp showbox=true|error=You must be logged in, <b>with an active subscription</b>, to access this file. |pid=53]<a href=http://yahoo.com>Click here to download this lesson</a>[/amp]

Yes, my bad..thanks.

 

But now I'm stuck at the preg_replace part. I'm using this..

 

 

                        $pattern = '%\[amp (.*?)\]". $protected_content ."\[\/amp\]%s';
                        $form = function_login_form();
                        $content = preg_replace($pattern, $form, $content);                        

 

...but apparantly, preg_replace is not able to find that pattern because it doesn't replace the pattern in the content with the form.

 

Any ideas?

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.