473,408 Members | 1,772 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,408 software developers and data experts.

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 11294
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
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...

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.