A
A
Alexey2017-04-19 18:11:46
PHP
Alexey, 2017-04-19 18:11:46

How to parse part of a text?

There is a text, tell me how to parse only part of it?
1. text bla bla bla , Moscow
How to parse text up to a comma and cut off the rest?
2. text bla bla bla 2017-06-13
How to parse only the date and display it?
Tell me how to do this in php, what commands can I use str_replace, date_parse_from_format?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Bard, 2017-04-19
@serg_small_developer

1) preg_match_all("/.*?\,/",    $variable(где лежит нужный текст),    $variable(куда будет вложен текст)  );
2) preg_match_all("/\d\d\d\d\-\d\d\-\d\d/",    $variable(где лежит нужный текст),    $variable(куда будет вложен текст)  );

regular expressions are the most primitive, but
str_replace is suitable for your options - this is for replacing with a regular
expression date_parse_from_format - getting information about a date in a specific format

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question