473,320 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Preg_Replace AJAX submitted text

3
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:
Expand|Select|Wrap|Line Numbers
  1. ... [<a href="#" onClick="edit('div1', 'advert');">edit</a>] 
  2. ... [<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)

Expand|Select|Wrap|Line Numbers
  1. $pattern     = '[... \[<a href="#" onclick="edit(\'^[a-zA-Z0-9]\', \'^[a-zA-Z0-9]\');">edit</a> 
  2. [PHP]$replace     = ' '; 
  3. [PHP]$newValue     = preg_replace($pattern, $replace, $divContent);
Could someone please help me with the right pattern statement for this?

Thanks
Jan 19 '08 #1
1 1680
Dormilich
8,658 Expert Mod 8TB
idea 1: replace '... [ (link) ]'
this only works, if the construction '... [ ]' is unique to those hyperlinks
Expand|Select|Wrap|Line Numbers
  1. $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 ( [ ] )
Aug 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: JDJones | last post by:
Just want to verify. I have a form and I want to parse any semi-colons out of the submitted info and replace with commas. Would this be the correct way to do it? $question1 = preg_replace(";",...
4
by: Sidharta | last post by:
Hi all, how come this doesn't work????? # convert to unix new lines $text = preg_replace("/\r\n/", "\n", $text); # remove extra new lines $text = preg_replace("/\n+/", "\n", $text); is...
4
by: Rob Meade | last post by:
Hi all, I played with my first bit of AJAX the other week and was pleasantly surprised that I achieved my goal..now I'd like to try something else.. Question... If I have an updatePanel,...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: pritisolank | last post by:
Hello Everyone, With that alert statment alert("calling validateme for "+document.form1.elements); in js things would work fine but if i remoe the form is simply getting submitted in firebug i can...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
3
by: Trammel | last post by:
Im accepting user input from a text-box on a webpage. I am then wanting to echo that back into the same box when the page is submitted. The problem I have is that the input COULD contain...
12
by: colt28 | last post by:
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.