THE SITUATION:
I need to cut a specific part of a string. That part will not always be the same in length and content.
The only thing i know is that it will always start with: and finish with:
All the content in the middle must cut out (head tag included).
THE QUESTION:
How can i cut a specific part of a string knowing only the begin and the end of that part?
EDIT:
For example from this string i have to remove the part that is contained into the head tag:
<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello!
</div>
</body>
</html>
How about the stupid-proof way?
<?php
$myString = "<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello!
</div>
</body>
</html>";
$begin = strpos($myString, '<head>');
$end = strpos($myString, '</head>');
$final = substr($myString, 0, $begin) . substr($myString, $end+7);
var_dump($final);
?>
How about this?
$str = "hello:evening:";
echo preg_replace("/\:[^)]+\:/","",$str);
This will give only "hello"