I am trying to delete a line from textarea post result, starting with “To”
My try:
$var = 'Date: __date\n"."Mime-Version: 1.0\nFrom: __From \nTo: __To\nSubject: __Subject \nReply-To: __Reply-To\nX-Job: __X-Job';
$text = preg_replace("/To(.*)$\n/s","",$var);
but it did not work.
i want this output
Date: __date\n"."Mime-Version: 1.0\nFrom: __From \nSubject: __Subject \nReply-To: __Reply-To\nX-Job: __X-Job'
Edit:
The last solution i used, which take into consideration that the input is from textarea
$text = preg_replace("/To.*?Subject:/s","Subject:",$var);
You need the
/mmodifier so that the^matches the start of each line, and then use this expression:I’m not using the
/smodifier, because that would cause.to match newlines as well, and that’s not what you want here.Demo
Btw, according to the specification, MIME headers may span multiple lines; I’m ignoring that in this answer 🙂