久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

獲取引號中的文本

Get text in quotes(獲取引號中的文本)
本文介紹了獲取引號中的文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

是否有一些函數可以只從變量的引號中獲取文本?
就像:

is there is some function that can take just text inside the quotes from the variable?
Just like:

$text = 'I am "pro"';
echo just_text_in_quotes($text);

我知道這個功能不存在..但我需要類似的東西.我在想 fnmatch("*",$text)但是這不能只回顯那個文本,它只是為了檢查.你能幫我么?謝謝.

I know that this function doesn't exist.. but I need something like that. I was thinking about fnmatch("*",$text) But this cant Echo just that text, It's just for check. Can you please help me? Thank you.

推薦答案

此函數將返回引號之間的第一個匹配文本(可能是一個空字符串).

This function will return the first matched text between quotes (possibly an empty string).

function just_text_in_quotes($str) {
   preg_match('/"(.*?)"/', $str, $matches);
   return isset($matches[1]) ? $matches[1] : FALSE;
}

您可以修改它以返回所有匹配項的數組,但在您的示例中,您在 echo 返回值的上下文中使用它.如果它返回一個數組,你將得到的只是 Array.

You could modify it to return an array of all matches, but in your example you use it within the context of echoing its returned value. Had it returned an array, all you would get is Array.

您最好編寫一個可以處理多次出現和自定義分隔符的更通用的函數.

You may be better off writing a more generic function that can handle multiple occurrences and a custom delimiter.

function get_delimited($str, $delimiter='"') {
    $escapedDelimiter = preg_quote($delimiter, '/');
    if (preg_match_all('/' . $escapedDelimiter . '(.*?)' . $escapedDelimiter . '/s', $str, $matches)) {
        return $matches[1];
    }
}

如果沒有找到匹配項,這將返回 null.

This will return null if no matches were found.

這篇關于獲取引號中的文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 草草草网站 | 久久久久国产一区二区三区 | 欧洲精品一区 | 成人免费小视频 | 天天色综网 | 成人精品一区亚洲午夜久久久 | 欧美影院久久 | 日韩视频a| 欧美一区二区三区,视频 | 99福利| 亚洲一区二区三区在线播放 | 精品国产综合 | 亚洲+变态+欧美+另类+精品 | 欧美成年黄网站色视频 | 精品成人 | 91在线电影 | 精品国产青草久久久久96 | 国产欧美精品一区 | 日韩精品色网 | h小视频| 91视频在线网站 | 欧美一区二区免费 | 国产精品视频播放 | 欧美综合一区二区 | 国产精品69毛片高清亚洲 | 日韩中文在线 | 久草综合在线 | 色婷婷九月 | 亚洲日本欧美日韩高观看 | www.亚洲视频| 免费一二区 | 精品91av| 久久综合狠狠综合久久综合88 | 玖玖色在线视频 | 欧美日韩在线一区二区 | 九九九国产 | 欧美黄色一区 | 99亚洲精品视频 | 人人做人人澡人人爽欧美 | 亚洲在线| 国产精品视频一区二区三区, |