explode

PHP case-insensitive explode()

自闭症网瘾萝莉.ら 提交于 2019-12-01 16:09:43
I have the following code: explode("delimiter", $snippet); But I want that my delimiter is case-insensitive. Michael Robinson Just use preg_split() and pass the flag i for case-insensitivity: $keywords = preg_split("/your delimiter/i", $text); Also make sure your delimiter which you pass to preg_split() doesn't cotain any sepcial regex characters. Otherwise make sure you escape them properly or use preg_quote() . explode('delimiter',strtolower($snippet)); Never use expensive regular expressions when more CPU affordable functions are available. Never use double-quotes unless you explicitly have

PHP case-insensitive explode()

拥有回忆 提交于 2019-12-01 14:18:33
问题 I have the following code: explode("delimiter", $snippet); But I want that my delimiter is case-insensitive. 回答1: Just use preg_split() and pass the flag i for case-insensitivity: $keywords = preg_split("/your delimiter/i", $text); Also make sure your delimiter which you pass to preg_split() doesn't cotain any sepcial regex characters. Otherwise make sure you escape them properly or use preg_quote(). 回答2: explode('delimiter',strtolower($snippet)); Never use expensive regular expressions when

PHP explode terms in to array, retain quoted text as single array item

随声附和 提交于 2019-12-01 14:07:47
I have the following string from a form... Opera "adds cross-platform hardware" "kicks butt" -hippies In general I've simply been using the following... $p0 = explode(' ',$string); However now I want to maintain any and all quote operators as a single array item instead of having them create individual items like "adds , cross-platform and hardware" . I want to have that string end up creating an array like this... Array ( [0] => 'Opera', [1] => 'adds cross-platform hardware', [2] => 'kicks butt', [3] => '-hippies' ) I generally prefer to not use regex for most things whenever possible. You

PHP explode terms in to array, retain quoted text as single array item

吃可爱长大的小学妹 提交于 2019-12-01 12:14:49
问题 I have the following string from a form... Opera "adds cross-platform hardware" "kicks butt" -hippies In general I've simply been using the following... $p0 = explode(' ',$string); However now I want to maintain any and all quote operators as a single array item instead of having them create individual items like "adds , cross-platform and hardware" . I want to have that string end up creating an array like this... Array ( [0] => 'Opera', [1] => 'adds cross-platform hardware', [2] => 'kicks

php explode string with Uppercase if lowercase letter exists before it without space

流过昼夜 提交于 2019-12-01 11:00:37
$str="Hello MotoBell RingsKing Speech"; I need explode this string by uppercase letter if lowercase letter exists before it. like this: $splitted=array( 0=>"Hello Moto", 1=>"Bell Rings", 2=>"King Speech" ); any ideas? I try use that reg_ex, but not working: $pieces = preg_split('/(?=[A-ZА-Я])/u', $str, -1, PREG_SPLIT_NO_EMPTY); var_dump(preg_split('/(?<=[a-z])(?=[A-Z])/', 'Hello MotoBell RingsKing Speech')) // array(3) { // [0]=> // string(10) "Hello Moto" // [1]=> // string(10) "Bell Rings" // [2]=> // string(11) "King Speech" // } 来源: https://stackoverflow.com/questions/24951067/php-explode

Why is my PHP multi dimensional array not working?

随声附和 提交于 2019-12-01 10:29:06
问题 My multi-dimensional array is working. But I cannot seem to use explode or in_array to limit the array when calling via $_GET <? $shop = array( array("red", "black", "blue", "green"), array("orange"), array("orange", "black"), array("pink", "yellow") ); foreach ($shop as $rowNumber => $row) { echo "<li><b>The row number $rowNumber</b>"; echo "<ul>"; foreach ($row as $col) { if (in_array($col, explode(' and ', $_GET['filter']))){ echo "<li>".$col."</li>"; } } echo "</ul>"; echo "</li>"; } ?>

SQL: Explode an array

佐手、 提交于 2019-12-01 06:46:09
I have a table that contains JSON objects. Each JSON object contains an array in square brackets, separated by commas. How can I access any element in the square bracket array, for example "Matt", using SQL? {"str": [ 1, 134, 61, "Matt", {"action.type":"registered","application":491,"value":423,"value2":12344}, ["application"], [], "49:0" ] } I am using 'Hive' ontop of Hadoop. If you know how to do this in SQL, that is fine :) You can do this in Hive as follows: First you need a JSON SerDe (Serializer / Deserializer). The most functional one I have seen is https://github.com/rcongiu/Hive-JSON

PHP: Explode using special characters

≯℡__Kan透↙ 提交于 2019-12-01 05:27:30
I'm working on a long string grabbed from a Session that uses "§" (Section sign) to group and divide different parts of the string. Example: "ArticleID | Title | Date § ArticleID | Title | Date § ArticleID | Title | Date" I want to put this into an array using: explode("§",$str); However, for some reason the character is totally ignored. I have simply used a different character instead to get this working but why does PHP not recognise it? Check the file encoding. This § can be being passed to explode() as "\xA7", "\xA7\x00" or "\xC2\xA7" depending if the PHP file is encoded as ASCII, UNICODE

how to count the words in a specific string in PHP?

拜拜、爱过 提交于 2019-12-01 03:13:44
I want to count the words in a specific string , so I can validate it and prevent users to write more than 100 words for example . I wrote this function but I don't think it's effective enough , I used the explode function with space as a delimiter but what if the user puts two spaces instead of one . can you give me a better way to do that ? function isValidLength($text , $length){ $text = explode(" " , $text ); if(count($text) > $length) return false; else return true; } Francesco Laurita Maybe str_word_count could help http://php.net/manual/en/function.str-word-count.php $Tag = 'My Name is

PHP: Explode using special characters

被刻印的时光 ゝ 提交于 2019-12-01 03:03:31
问题 I'm working on a long string grabbed from a Session that uses "§" (Section sign) to group and divide different parts of the string. Example: "ArticleID | Title | Date § ArticleID | Title | Date § ArticleID | Title | Date" I want to put this into an array using: explode("§",$str); However, for some reason the character is totally ignored. I have simply used a different character instead to get this working but why does PHP not recognise it? 回答1: Check the file encoding. This § can be being