There is a variable that contains the date:

$output="<span class="date-display-single __web-inspector-hide-shortcut__" property="dc:date" datatype="xsd:dateTime" content="2016-05-10T09:00:00+03:00">10-05-2016 09:00</span>"; 

the task is to clear it from html and lead to this:

 $output="10-05-2016 09:00"; 

Tell me on my example, how can this be done?

    3 answers 3

     <?php $output = '<span class="date-display-single __web-inspector-hide-shortcut__" property="dc:date" datatype="xsd:dateTime" content="2016-05-10T09:00:00+03:00">10-05-2016 09:00</span>'; $date = strtotime(strip_tags($output)); echo date("Ymd H:i:s", $date); 
    • echo date("dmY H:i", $date); To be as the author asks - jekaby
    • What as the author asks simply enough strip_tags without translation to the date and back :) - Mike
    • oh well then I need to translate, thank you) - Evgeny Shevtsov
    • @Mike yes, you can just strip_tags, but coercion of $otput to the timestamp has some advantages - for example, you can change the date display format. - S. Pronin
    • @Mike Well, it says> clean it from html and lead to this form. Those. still need to bring to mind :) - jekaby

    You can cut a substring by markers> <i. find the first occurrence of the marker> and throw out this piece and then find the market <and throw out everything after it

    • in person, I myself understand it, but on php I have no idea how to do it, I would on php - Evgeny Shevtsov
    • It was your variant that interested, the answer below is of course the shortest and effortless, but it is more interesting how to replace the line if it starts with "Ivan" and ends with "Ivan" - Evgeny Shevtsov

    From the opposite. Since the date format is known, we do not remove tags around it, but look for the date with a regular expression. For example, so \d.-\d.-\d{4} \d.:\d.

    • but how can this option be turned? it's also interesting just how to replace the lines, if they start with "ivan" and ends with "ivanov", with "just a line" - Evgeny Shevtsov
    • regex101.com/r/hW2vO8/1 - to play around - Sergey Mitrofanov