explode

PHP exploding a string while keeping delimiters

时光毁灭记忆、已成空白 提交于 2019-12-12 05:10:13
问题 For my project I needed to analyze different sentences and work out which ones were questions by determining if they ended in question marks or not. So I tried using explode but it didn't support multiple delimiters. I temporarily replaced all punctuation to be chr(1) so that I could explode all sentences no matter what they ended with (., !, ?, etc...). Then I needed to find the last letter of each sentence however the explode function had removed all of the punctuation, so I needed some way

Editing an imploded string

半腔热情 提交于 2019-12-12 03:32:23
问题 I have an application in which I can assign task like cleaning the bathroom, washing the car and etc. I can assign a single task to let's say 3 to 4 persons using the code below if (isset($_POST["btnassign"])){ $proj = $_REQUEST['projhid']; $analyst = $_POST['analyst']; $commaList = implode('| ', $analyst); $queupass = "UPDATE projects set assignedto='$commaList', assignedby = '$uname' where projectname='$proj'"; $queresupass = odbc_exec($conn,$queupass); $notifassign = "New Project

PHP - Using implode, explode, and array_unique to autopopulate a dropdown menu from two SQL columns of comma-separated keywords

我与影子孤独终老i 提交于 2019-12-12 02:18:44
问题 I have an SQL database with a "category" keyword (only one allowed) and "issues" keywords (multiple comma-separated words). I am trying to make a auto-populating drop-down keyword select menu by selecting all the keywords from the "category" and "issues" columns, turning both returned arrays into comma-separated strings with implode, then combining the strings and exploding the comma-separated strings into an array, while removing duplicate entries with array_unique. But it's not working. I

Explode string into array with key and value

徘徊边缘 提交于 2019-12-12 02:03:21
问题 I've a string like this: $mystring = '{"1":"4","2":"2","3":"3"}'; I need to explode to something like this: array( "1" => "4", "2" => "2", "3" => "3" ) I use php 5.4. 回答1: Just use json_decode. $dd = json_decode($mystring, true); var_export($dd); 回答2: you "string" is very like json so maybe try json_decode() 回答3: you should use the json decode function, your string looks like json. The second argument tells to make it as an array, not an object. json_decode($mystring, true); 来源: https:/

Wrap Text in imagettftext()

亡梦爱人 提交于 2019-12-12 01:59:39
问题 i got this script to generate an image out of a random jpg in a directory, adding a random slogan from a database: <?php header('Content-type: text/html; charset=utf-8'); include '../connect.php'; require_once 'random.php'; $timestamp = time(); $date = date("d.m.Y_G", $timestamp); $slogan = $mysqli->query("SELECT `text` FROM `slogans` ORDER BY RAND() LIMIT 1"); $slogan_txt = $slogan->fetch_assoc(); $bg = get_rand_img('../../images/'); $imgPath = '../../images/' .$bg; $text = $slogan_txt[text]

PHP explode() not work with “ - ” character

妖精的绣舞 提交于 2019-12-12 01:41:30
问题 I want to substring the text, ex. "Hello - How are you?" by using this code $text= "Hello - How are you?"; $strings = explode(' - ',$text); echo $strings[0]; // Hello echo $strings[1]; // How are you it will not work, because of ' - '. If i change to: $text= "Hello-How are you?"; $strings = explode('-',$text); echo $strings[0]; // Hello echo $strings[1]; // How are you it's ok. Can someone help me? Thank you. 回答1: I had the same problem, after an hour of investigating, turns out that texts

Find out most popular words in MySQL / PHP

孤街浪徒 提交于 2019-12-11 20:05:47
问题 I have a database with almost 100,000 comments and I would like to detect the most used words (using stop words to avoid common words). I want to do this only one time, and then use a few of the most popular words to Tag the comments that contains them. Can you help me with the Query and PHP code to do this? Thanks! 回答1: The easiest approach I guess would be: Create two new tables: keywords (id, word) and keywords_comments (keyword_id, comment_id, count) keywords saves an unique id and the

Mysql: Getting Count of Comma Separated Values With Like

假如想象 提交于 2019-12-11 19:07:27
问题 I decided to use favs (id's of users which marked that post as a favorite) as a comma separated list in a favs column which is also in messages table with sender,url,content etc.. But when I try to count those rows with a query like: select count(id) from messages where favs like '%userid%' of course it returns a wrong result because all id's may be a part of another's For example while querying for id=1 it also increase the counter for any other content that is favorited by user id 11... Can

PHP Notice: Undefined offset error when importing from .csv [duplicate]

依然范特西╮ 提交于 2019-12-11 18:51:17
问题 This question already has answers here : “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP (28 answers) Closed 2 years ago . I'm continually getting the above error when importing data from csv using the following code: $csv_data=file_get_contents("data3_received.csv"); foreach(preg_split("/((\r?\n)|(\r\n?))/", $csv_data) as $line){ list($service_id, $ki3) = explode(',', $line,2); The data imports as expected but the error log is filling up as

PHP: Parsing Comma-Separated Values Between Square Brackets into Multi-Dimensional Array

笑着哭i 提交于 2019-12-11 18:49:30
问题 I have the following string: [aaaa,bbbb,cccc] [aaaa,bbbb,cccc] [aaaa,bbbb,cccc] [aaaa,bbbb,cccc] [aaaa,bbbb,cccc] and would like to parse this string into a multidimensional array that would look like 0 > ( 0 > aaaa, 1 > bbbb, 3 > cccc), 1 > ( 0 > aaaa, 1 > bbbb, 3 > cccc), 2 > ( 0 > aaaa, 1 > bbbb, 3 > cccc) How would I do this? Many Thanks! 来源: https://stackoverflow.com/questions/13735147/php-parsing-comma-separated-values-between-square-brackets-into-multi-dimension