Suppose I have this entire text contained in a single string variable:
[text]
--=_b6a990e35093cac7efaddd6539ff8b60
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=us-ascii;
charset=us-ascii
test1
test2
test3
[/text]
Some of you may recognize this as part of the body of MIME email, that's because it is! Anyways, I need a script which can check the Content-Type of this block of text. If the Content-Type is text/plain I need the script to then delete everything in the string up until test1.
Proceeding test1 should be \r\n\r\n so I can do a replace(substr(STRING, 0, strpos(STRING, '\r\n\r\n')), '') or some variation like that (there's probably a syntax error in there). I'm not sure how to do the first part of traversing the string and checking the Content-Type.
Any advice?
Thanks,
Shawn
find and remove chunk of a string, (more than replace())
Moderator: General Moderators
-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: find and remove chunk of a string, (more than replace())
Easiest way would probably be with regular expressions.
Code: Select all
if (!preg_match('#Content-Type:\s*([^/]+/[^;\r\n]+)\r\n#i', $text, $matches) || $matches[1] == "text/plain") {
// whatever
}-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: find and remove chunk of a string, (more than replace())
aahhhh yes.... regular expressions..... those things that I need to familiarize myself with....
Thank you
Thank you