We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24495
    • 407 Posts
    Need a litte help in PHP.
    I have a page with text content (by RTE). Text ends in HTML with a </p> and, depending on RTE behaviours, with following blanks or line breaks (not visible).
    After that content I have an external link filled by a tv. A snippet produces a link source like
    <p><span class="linking"><a href="link-target">link-target-text</a></span></p>


    Now I use a modified ChunkReplace plugin for changing "the last closing p plus opening p plus linking-span" to "blank plus opening linking-span". Here is the code:
    /**
     * MODIFIED ChunkReplace Plugin 
     * Written By Jason Coward (OpenGeek) - June 22, 2006
     *
     * Version 1.0
     *
     * Events: OnWebPagePrerender
     *
     * Usage: Please setup "phrase_to_replace" and "myChunk" to your requirments.
     *
     *
     */
    
    $e= & $modx->Event;
    switch ($e->name) {
        case "OnWebPagePrerender" : //mo register only for backend
            $modx->documentOutput= str_replace('</p><p><span class="linking">', ' <span class="linking">', $modx->documentOutput);
            break;
    
        default :
           return; // stop here - this is very important. 
            break;
    }


    What I get is a text ending with an inline link like:
    text text text [this is a link to anywhere].

    The plugin now works ok if there is no blank after last paragraph, but if there are hidden characters it fails.
    What I must include into the plugin to delete ALL unwanted characters between the closing p and opening span?



    EDIT: I use now PHx and strip all unwanted characters from content with [*content:strip*]. With this the snippet code comes after closing p of content without any blanks. And now the modified plugin works fine.