Jump to content

Strip Words/Lines from string


christo16

Recommended Posts

Hello, Lets say I have a variable that contains some text and xml.

$file = "HTTP/1.1 207 Multi-Status
Content-Length: 1341
Accept-Ranges: bytes
Vary: accept-encoding
Server: Twisted/2.5.0 TwistedWeb/[twisted.web2, version 0.2.0] TwistedCalDAV/2.0 (unknown)
Last-Modified: Wed, 04 Jun 2008 21:18:37 GMT
DAV: 1, access-control, calendar-access, calendar-schedule, calendar-availability, inbox-availability, calendar-proxy, calendarserver-private-events
ETag: \"3D2D-594-484706AD\"
Date: Wed, 04 Jun 2008 21:23:25 GMT
Content-Type: text/xml
Connection: close

<?xml version='1.0' encoding='UTF-8'?>
  XML GOES HERE
</multistatus>";

 

How do I strip out the text- from "HTTP/1.1 207 Multi-Status" to "Connection: close", including the blank line below connection close?

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/108765-strip-wordslines-from-string/
Share on other sites

<?php
$file = "HTTP/1.1 207 Multi-Status
Content-Length: 1341
Accept-Ranges: bytes
Vary: accept-encoding
Server: Twisted/2.5.0 TwistedWeb/[twisted.web2, version 0.2.0] TwistedCalDAV/2.0 (unknown)
Last-Modified: Wed, 04 Jun 2008 21:18:37 GMT
DAV: 1, access-control, calendar-access, calendar-schedule, calendar-availability, inbox-availability, calendar-proxy, calendarserver-private-events
ETag: \"3D2D-594-484706AD\"
Date: Wed, 04 Jun 2008 21:23:25 GMT
Content-Type: text/xml
Connection: close

<?xml version='1.0' encoding='UTF-8'?>
  XML GOES HERE
</multistatus>";

$file = preg_replace('~(.+?)<\?xml\s*version=~s', '$1', $file);
echo $file;
?>

 

Anyone have anything better?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.