php substr() function with utf-8 leaves � marks at the end

The comments above are correct so long as you have mbstring enabled on your server. $var = “Бензин Офиси А.С. также производит все типы жира и смазок и их побочных продуктов в его смесительных установках нефти машинного масла в Деринце, Измите, Алиага и Измире. У Компании есть 3 885 станций технического обслуживания, включая сжиженный газ … Read more

Extract string before “|” [duplicate]

We can use sub sub(“\\|.*”, “”, str1) #[1] “ABC” Or with strsplit strsplit(str1, “[|]”)[[1]][1] #[1] “ABC” Update If we use the data from @hrbrmstr sub(“\\|.*”, “”, df$V1) #[1] “ABC” “ABCD” “ABCDE” “DEF” “GHI” “BCDE” These are all base R methods. No external packages used. data str1 <- “ABC|DEF|GHI ABCD|EFG|HIJK ABCDE|FGHI|JKL DEF|GHIJ|KLM GHI|JKLM|NO|PQRS BCDE|FGHI|JKL”

Get last field using awk substr

Use the fact that awk splits the lines in fields based on a field separator, that you can define. Hence, defining the field separator to / you can say: awk -F “https://stackoverflow.com/” ‘{print $NF}’ input as NF refers to the number of fields of the current record, printing $NF means printing the last one. So … Read more

Using PHP substr() and strip_tags() while retaining formatting and without breaking HTML

Not amazing, but works. function html_cut($text, $max_length) { $tags = array(); $result = “”; $is_open = false; $grab_open = false; $is_close = false; $in_double_quotes = false; $in_single_quotes = false; $tag = “”; $i = 0; $stripped = 0; $stripped_text = strip_tags($text); while ($i < strlen($text) && $stripped < strlen($stripped_text) && $stripped < $max_length) { $symbol … Read more