![]() Topic awaiting preservation: Regex Help in PHP (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: Australia |
![]() Hi all, trying to do some formatting on some existing code... code: Case 1 <form id="200681 21520 27; some stuff" method="post"> Case 2 <form id=2006812152027somestuff method="post">
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
![]() Why not run two different regexes |
Paranoid (IV) Inmate From: Australia |
![]() I ended up doing this, but its less than ideal. If the format of my tag changes then it will no longer work. It does however work for either scenario in the one regex, i would rather have 2 that work properly however code: preg_replace('!<form id=.* (.*) (.*) (.*) ?>!i','<form \\1 \\2 \\3>'
|
Paranoid (IV) Inmate From: Australia |
![]() Okay i think i have it, here is what i ended up with: code: preg_replace('!<form (id="[^"]+")\s+(.*)>!i','<form \\2>', $strHtmlParsed); $strHtmlParsed = preg_replace('!<form (id=\d+\S+)\s+(.*)>!i','<form \\2>', $strHtmlParsed);
|
Bipolar (III) Inmate From: f(x) |
![]() code: <form\s+id=("?)([^"]+|\S+)\1\s+method="post"> id contents are in $2 |
Paranoid (IV) Inmate From: Australia |
![]() Hmm wouldnt the id contents be in 1? and the rest of it in 2? |
Bipolar (III) Inmate From: |
![]() A simplified regex for both types, including (working) example code: code: $string = '<form id="200681 21520 27; some stuff" method="post">\n <form id=2006812152027somestuff method="post">'; echo htmlentities(preg_replace('/<form (id=("[^"]+"|[^\s]+)\s+)(.*)>/i', "<form \\3>", $string));
|
Paranoid (IV) Inmate From: Australia |
![]() Thanks all, hard to find examples like these |
Bipolar (III) Inmate From: f(x) |
![]() |