473,488 Members | 2,516 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Replace everything between two strings?

I need to replace everything between and including two snippets of HTML
code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d
<B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I want to
remove them and everything in between, including /n line breaks.

Can't figure out the regex in PHP to do this.... any ideas?


Jul 17 '05 #1
2 11296
do********@nowhere.com idiotically stated:
I need to replace everything between and including two snippets of
HTML code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf
d <B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I
want to remove them and everything in between, including /n line
breaks.

Can't figure out the regex in PHP to do this.... any ideas?


use stristr().

First split up the whole string based on your first delimiter
(</table></td>....). take the end part of that result (which is now
everything after your first delim). Then split it up again, but use your
2nd delimiter (<br>). Use the beginning part of that result. you now have
a string that is between your two delimiters.

now use that string and stristr again on the original, full string, and
simply replace it with a empy space.

--
brian ... brian@cc
www.brianculler.com
Jul 17 '05 #2
Uzytkownik "DesignGuy" <do********@nowhere.com> napisal w wiadomosci
news:o0n8c.83725$1p.1228208@attbi_s54...
I need to replace everything between and including two snippets of HTML
code, for example:

</table></td></tr></table> klsdjff sd fsd fs fs df sdfs df sdf sd fsf d
<B><P> sfd sd fsdfs <br>

The </table></td></tr></table> and <br> parts will be the same. I want to
remove them and everything in between, including /n line breaks.

Can't figure out the regex in PHP to do this.... any ideas?


$text = preg_replace('!</table></td></tr></table>.*?<br>!s', '', $text);

The key here is the s modifier, which tells PCRE that you want the dot to
match \n as well.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5212
by: Marco Leist | last post by:
hello, i´d like to replace certain strings in a XML-Document with other ones. Thereby the structure (tags)of the source-xml should be preserved completly, the strings that should be replaced are...
1
10095
by: Bruno | last post by:
Hello, I don't know well XML and I can't figure out how to solve this problem .. I need to replace some strings inside a text using XSL and inside a for-each statement (the list of strings to...
2
3374
by: Christopher Beltran | last post by:
I am currently trying to replace certain strings, not single characters, with other strings inside a word document which is then sent to a browser as a binary file. Right now, I read in the word...
6
5380
by: Brett | last post by:
I've been trying different methods for replacing escaped strings. None work. I even have a custom Replace() method but still can't get what I need. Some of the characters I need to replace are:...
2
3834
by: jason | last post by:
Hello. I just converted some data to to sql2000 into a TEXT type field. I needed to remove all tabs from the data and now want to remove extra lines too. As we know, SQL2000's replace function...
4
22975
by: Lauren Wilson | last post by:
Hi folks, We have a need to replace sub strings in certain message text. We use the Office Assistant to display help and often use the imbedded formatting commands. Those of you who have used...
4
5489
nev
by: nev | last post by:
I would like to know if there is a faster way of doing this. str = "(0918)346-5303" strings.replace(str,"(","") strings.replace(str,")","") strings.replace(str,"-","") after that str will...
3
10012
by: Ned White | last post by:
Hi All, To replace some substrings in a string value, i use Regex.Replace method mulptiple times like; strmemo = "new Data for user; Name:@@Name , Surname:@@Surname, Address:@@Address";...
5
2300
by: buu | last post by:
I have an function that replaces some string from a huge text that I run very often... So, I wanted to speed it up... I was using String and StringBuilder. But, I was wandering should same...
0
7142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5445
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4875
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4565
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.