explode

Exploding a string into equal portions

穿精又带淫゛_ 提交于 2019-12-24 09:59:36
问题 $str = "Hello fri3nd, you're looking good today! What a Great day this is! How fancy and cool!"; $pieces = explode(" ",$str, 3); print_r($pieces); so this gives me $pieces[0] = 'Hello', $pieces[1] = 'fri3nd' ... and the rest of the string is all shoved into $pieces[3]`. How can I explode into every 3 or 4 words? 回答1: Maybe:? <?php $str = "Hello fri3nd, you're looking good today! What a Great day this is! How fancy and cool!"; $array = array_map(create_function('$a', 'return implode(" ", $a);'

PHP problems parsing a bible book string

自古美人都是妖i 提交于 2019-12-24 04:43:07
问题 I hope you can help me. I have a string like the following Luke 1:26-38 And I would like to be able to break it up into tokens or individual variables so that I can use the variables in an SQL query. I've tried using explode, however I've only been able to make it explode on one character such as : or - My string has : and - and also a space between the name and the first number. My goal is to have: $name = Luke; $book = 1; $from = 26; $to = 38; Is anyone able to help please. Many thanks 回答1:

Best way to chop a signature off an email body

有些话、适合烂在心里 提交于 2019-12-24 00:43:14
问题 I am parsing out some emails. Mobile Mail, iPhone and I assume iPod touch append a signature as a separate boundary, making it simple to remove. Not all mail clients do, and just use '--' as a signature delimiter. I need to chop off the '--' from a string, but only the last occurrence of it. Sample copy hello, this is some email copy-- check this out -- Tom Foolery I thougth about splitting on '--', removing the last part, and I would have it, but explode() and split() neither seem to return

Php explode using 1 fixed character and 2 random numbers

ぐ巨炮叔叔 提交于 2019-12-23 05:40:06
问题 I have created a task that will read from an xml file, and then store information to a database. During the process it strips out unnecessary information, and changing other parts. When reading the XML file, I get information as follows: <time>2/1/2016 16:49:15</time> <type>GOALS</type> <event>FC HALIFAX TOWN 2-2 Lincoln City</event> I am getting stuck when working with the 'event'. I want to explode the event, so that I am left with: $team[0] = "FC HALIFAX TOWN" $team[1] = "Lincoln City" I

Explode a string in php excluding the ', ' within braces

旧街凉风 提交于 2019-12-22 10:30:54
问题 I have a string of this- $str = "field1.id as field1, DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2, field3.name as field3"; Need to explode this into array with , as this: $requiredArray = array( 0 => field1.id as field1, 1 => DATE_SUB(field2, INTERVAL (DAYOFMONTH(field2)-1) DAY) as field2 2 => field3.name as field3 ); I've tried with explode but it doesn't works: $requiredArray = explode(', ', $str); // doesn't work as "DATE_SUB(field2, INTERVAL ..." also gets exploded Any

Explode contents of a txt file into array

泪湿孤枕 提交于 2019-12-22 09:15:45
问题 I´m having trouble exploding contents of a .txt file (structure below): 01Name 1 02whatever contents 03whatever contents ------------------- 01Name 2 02whatever contents 03whatever contents As you can see, the "delimiter" is "-------------------". Now, the question is: how to explode this file into an array, so I can search for a specific name and display that block´s contents? I´ve tried to explode like this: header("Content-type:text/plain"); $file = fopen("cc/cc.txt", "r"); while (!feof(

Explode to array and print each element as list item

前提是你 提交于 2019-12-21 02:55:07
问题 I have a set of numbers in a table field in database, the numbers are separated by comma ','. I am trying to do the following: Step 1. : SELECT set of numbers from database and explode it to array : $array = explode(',', $set_of_numbers); Step 2. : Print each element of the array as list item by using foreach loop : foreach ($array as $list_item => $set_of_numbers){ echo "<li>"; print_r(array_list_items($set_of_numbers)); echo "</li>";} Please anybody tell me what is wrong. Thank you. 回答1:

PHP & MySQL: fetch images from database

99封情书 提交于 2019-12-20 19:47:09
问题 I have uploaded multiple images and path of all the images have been stored together. Using explode I have separated them and now I wish to echo them in a carousel Code that I am using is: <?php $con=mysqli_connect("localhost","root","","db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $idd = $_GET['id']; echo "<header id='myCarousel' class='carousel slide'>"; /* Indicators */ echo"<ol class='carousel-indicators'>"; echo"

PHP: How to turn a string that contains an array expression in an actual array?

邮差的信 提交于 2019-12-20 04:13:48
问题 I have an array of user inputs ($atts) as key=>value pairs. Some of the values could be written as an array expression, such as: 'setting' => 'array(50,25)' In those cases, I would like to convert the array expression contained in that string into an actual array. So the output would be something like: $atts = array( 'setting' => array(50,25), 'another' => 'not written as an array expression' ) Written logically, the code would be: For each key=>value pair in the array $atts... if the value

replace comma between double quotes using preg_replace [duplicate]

末鹿安然 提交于 2019-12-20 03:31:28
问题 This question already has answers here : str_getcsv() alternative for older PHP version, gives me an empty array at the end (3 answers) Closed 6 years ago . I have a csv file like this Number,Name,UG College,UG University,PG College,PG University 1100225,Lakshmin,pkrrrr College,"PKRRRRR University, Choice",nandhaaaaa,"Nandhaa University, Kumali" While reading the file I want to replace comma only inside double quotes . Thanks in advance . 回答1: $string = '1100225,Lakshmin,pkrrrr College,