Preg_Replace AJAX submitted text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sbudah
    New Member
    • Jul 2007
    • 3

    Preg_Replace AJAX submitted text

    Hi All,

    I have relatively moderate experience with PHP but preg_replace is not one of my strong points. I need HELP with the following:

    I have 5 [HTML]<div>[/HTML] tags whose values are sent to a PHP page that creates a textbox with the initial value being whatever was in the posted div (posted using AJAX).

    Part of the innerHTML on the div is the link that activates the ajax function:
    Code:
    ... [<a href="#" onClick="edit('div1', 'advert');">edit</a>] 
    ... [<a href="#" onClick="edit('div2', 'content');">edit</a>]
    ... etc

    I would like to strip the text link with the leading dots. I thought preg_replace would be a solution here so I wrote the following (obviously horrible bad)

    Code:
    $pattern 	= '[... \[<a href="#" onclick="edit(\'^[a-zA-Z0-9]\', \'^[a-zA-Z0-9]\');">edit</a> 
    [PHP]$replace 	= ' '; 
    [PHP]$newValue 	= preg_replace($pattern, $replace, $divContent);
    Could someone please help me with the right pattern statement for this?

    Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    idea 1: replace '... [ (link) ]'
    this only works, if the construction '... [ ]' is unique to those hyperlinks
    Code:
    $pattern = '@... \[[^\]]\]@';
    note: I use '@' as delimiter, but you can use anyone you like

    idea 2: when you use AJAX you can as well use javascript to remove the hyperlinks (this depends upon whether they are the only hyperlinks)

    a note to your posted pattern:
    - '; at the end of statement missing
    - final delimiter ( [ ) missing
    - invalid delimiter ( [ ) ?
    - ^ only at start of pattern or inside a class ( [ ] )

    Comment

    Working...