All expensive time of day.

There is a text example:

I am engaged in the manufacture, assembly and installation of advertising signs, large letters and banners. Also typing on the material. 890000000. I do everything from business cards to signs. I carry out the whole range of services. # typography @ tipografia

The essence of the function is to cut the phone from the text (my regular expression /89\d{9}/ ) and cut the hashtag #типография@tipografia (the only dynamic part in the “typography” tag is the rest does not change #******* @tipografia )

and output 3 variables from the function:

  1. $a which contains the source code without a phone and hashtag.
  2. $b which contains the phone "89000000000" .
  3. $c which contains the hashtag "#типография@tipografia" .

Help me please.

    2 answers 2

    One option is to first get the number and email from the line, then delete them. Returning values ​​from the function can be more convenient, I used the compact () function for this, but you can simply declare an array, collect all the data in it and return the array:

     <?php $str = 'Занимаюсь изготовлением, сборкой и установкой Рекламных вывесок, объемных букв и баннеров. Также печатаю на материале. 89000000000. Все делаю от визиток до вывесок. Весь спектр услуг выполняю. #типография@tipografia'; extract(str_parse($str)); // $text == текст // $tel == телеф.номер // $email == эл.адрес function str_parse($str) { preg_match_all('~\b89\d{9}\b|#[^#\s]+~', $str, $arr); $text = preg_replace('~\b89\d{9}\b\.?|#[^#\s]+~', '', $str); $tel = $arr[0][0] ?? false; $email = $arr[0][1] ?? false; return compact('text', 'tel', 'email'); } ?> <!-- Подставить переменную с номером телефона $tel --> <textarea rows="17" cols="47" name="text" ><?= $tel ?></textarea> 
    • Thank! Tell me, please, I call the function by passing it a variable with the text str_parse ($ text), how to make the number appear? My code is: <textarea rows = "17" cols = "47" name = "text"> <? str_parse ($ text); ?> </ textarea> - Dmitriy

    Another option is possible.

     $text = 'Занимаюсь изготовлением, сборкой и установкой Рекламных вывесок, объемных букв и баннеров. Также печатаю на материале. 89000000000. Все делаю от визиток до вывесок. Весь спектр услуг выполняю. #типография@tipografia'; $number = preg_replace('~[^0-9]+~','',$text); $hesh = stristr($text, '#'); $text = str_replace($number, "", $text); $text = str_replace($hesh, "", $text); 

    Answer:

     89000000000 #типография@tipografia Занимаюсь изготовлением, сборкой и установкой Рекламных вывесок, объемных букв и баннеров. Также печатаю на материале. Все делаю от визиток до вывесок. Весь спектр услуг выполняю.