PHP - Trying To Split A List Of Text Into 3 Variables
so far I have: $crawler->filter('li.date, dt > a, li.style')->each(function ($node) { $output = $node->text()."\n"; $array = explode("\n", $output); $data = array_chunk($array, 3); // print_r($data); foreach ($data as $row) { [$date, $title, $type] = array_pad($row, 3, null); // here you have your variables print 'Date: '.$date; print 'Title: '.$title; print 'Type: '.$type; } }); and this outputs: QuoteDate: Saturday 13th Jun 2020Title: Type: Date: Alice in Chains UKTitle: Type: Date: Metal/ RockTitle: Type: Date: Monday 29th Jun 2020Title: Type: Date: Cage the ElephantTitle: Type: Date: Funk/ RockTitle: Type: Date: Friday 31st Jul 2020Title: Type: Date: The CureheadsTitle: Type: Date: Indie/ RockTitle: Type: Date: Thursday 20th Aug 2020Title: Type: Date: CreeperTitle: Type: Date: PunkTitle: Type: Date: Saturday 22nd Aug 2020Title: Type: Date: Fleetwood BacTitle: Type: Date: Pop/ RockTitle: Type: Date: Monday 31st Aug 2020Title: Type: Date: GZATitle: Type: Date: Hip HopTitle: Type: Date: Saturday 5th Sep 2020Title: Type: Date: Cock SparrerTitle: Type: Date: Only $date variable is set for each?! please help??
it should be: Date: Saturday 13th Jun 2020Title: Alice in Chains UKType: Metal/ Rock Date: Monday 29th Jun 2020Title: Cage the ElephantType: Funk/ Rock and so on.... Similar TutorialsHi , I have one question .. Can I split showing of content of dynamic list in 2 parts , when I echo list in code .. Code: [Select] <?php // Run a select query to get my letest 8 items // Connect to the MySQL database include "../connect_to_mysql.php"; $dynamicList = ""; $sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 8"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $product_name = $row["product_name"]; $price = $row["price"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); $dynamicList .= '<table width="100%" border="2" cellspacing="2" cellpadding="2"> <tr> <td width="17%" valign="top"><a href="product.php?id=' . $id . '"><img style="border:#666 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="77" height="102" border="2" /></a></td> <td width="83%" valign="top">' . $product_name . '<br /> $' . $price . '<br /> <a href="product.php?id=' . $id . '">View Product Details</a></td> </tr> </table>'; } } else { $dynamicList = "We have no products listed in our store yet"; } mysql_close(); ?> Code: [Select] <p><?php echo $dynamicList; ?><br /> </p> It works ok, and putting my files, everything works, but when I put 8 pictures with price and other details, it just show one image with details and another image below with details, and the third image below and so on .. Can I split dynamic list to show 4 images with details on the left side and 4 on the right side? Thank you in advance for help , if is possible Is it possible to split a variable into 2 variables? /// I have this sentence $item = "Below Telegraph Hill, Smallwork Canvas Edition"; /// And I want to be able to do this $item = "Below Telegraph Hill" ; $medium = "Smallwork Canvas Edition"; Is it possible to find the comma in a string, and remove the comma & everything before or after it? Any recommendations would be appreciated. Hi. I will try and explain simply.
I have a list of item codes eg.
size1 Acolor1
size1 Bcolor3
size1 Bcolor1
size1 Acolor3
size1 Acolor4
size2 Acolor1
size3 Bcolor1
size3 Bcolor2
size3 Bcolor2
size3 Acolor1
I want to take these and split them into parts:
size1 Acolor2
size1 Bcolor3
etc.
Then I want to create a form with 2 dropdowns. The first option would just have all unique sizes so:
size1
size2
size3
Then when one is selected, option 2 would show the colours available in that size.
Is there a standard way of doing this? Can I use PHP to create the array and then jquery to display and hide the options?
I'm totally stuck and i'm not just looking for somebody to code it all for me. any help would be greatly appreciated
thanks
Sam
I have text field in database, where I have let's say 5000 words. I want to split this text having 5000 words in pages, each one having 500 words. How can I realise this ? A practical example would be appreciate ! Thank you in advance. This script is supposed to run in the command line. Like the title says, I need to: Import some columns (input the names with an argument) from a .CSV file Split the column into blocks of 500 lines Translate this pieces Put them back into the original file I already have some code but it is unfinished and not working: <?php //name of the .CSV file $filename = $argv[1]; //name of the column to be translated $header_name = $argv[2]; //open file $file_handle = fopen($filename, "r"); $i=0; $j=0; $counter = 0; $translated = ''; $string = ''; while (!feof($file_handle) ) { $counter++; $line_of_text = fgetcsv($file_handle, 1024); //find the column id that contains the header name. // headers are always on the the first line if ( $counter == 1 ){ while ($line_of_text[$i] != $header_name) $i++; $header_id = $i; } //create the blocks $string .= $line_of_text[$i]; if ($counter % 500 == 0) { $gt = new GoogleTranslateWrapper(); $translated .= $gt->translate($string, "en"); } } //Write the translate column in the same .CSV file fclose($file_handle); ?> Any help in rewriting this to work? Hi, In my mysql database i have a text input option, in the registration form and edit my details form i have a multiple select dropdown list, which user selects options to populate the text input box, which ultimately populates the text field in the mysql database. All works perfectly. The dropdownlist consists of 3 parts <optgroups> first is current selection (what is the usesr current selection)works fine, The second <optgroup> is existing words, what words we(the site) have given as options, and the third <optgroup> is the words that others have used. This is where im having a small problem. Because its a text field when i call the data from the database, it calls the entire text box as a single option in my select list.. I want to break the words in the text field (at the comma) and have them listed each one as an option in the select list. Example what i need: Words in text box:(my input allows the "comma") word1, word2, word3, word4, word5, word6, How i want them called/displayed: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> here's my code: $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $original_functionsexperience =doSelectSql($query,1); $query = "SELECT allwords FROM #__functions_experience WHERE profile_id = '".(int)$profileId."' LIMIT 1"; $functionsexperiencelist=doSelectSql($query); $funcexpList ="<select multiple=\"multiple\" onchange=\"setFunctionsexperience(this.options)\">"; foreach ($functionsexperiencelist as $functionsexperienceal) { $selected=""; if ($functionsexperienceals->allwords == $original_functionsexperience) $selected=' selected="selected"'; $allwords=$functionsexperienceal->allwords; $funcexpList .= "<optgroup label=\"Current selection\"> <option value=\"".$allwords."\" ".$selected." >".$allwords."</option> </optgroup> <optgroup label=\"Existing Words\"> <option value=\"existing1,\">existing1</option> <option value=\"existing2,\">existing2</option> <option value=\"existing3,\">existing3</option> <option value=\"existing4,\">existing4</option> <option value=\"existing5,\">existing5</option> <option value=\"existing6,\">existing6</option> </optgroup> <optgroup label=\"Others added\"> //heres problem <option value=\"".$allwordsgeneral."\">".$allwordsgeneral."</option> </optgroup>"; } $funcexpList.="</select>"; $output['FUNCEXPLIST']=$funcexpList; The result im getting for optgroup others added: word1, word2, word3, word4, word5, how can i get it like this: <option value=\"word1\">word1</option> <option value=\"word2\">word2</option> <option value=\"word3\">word3</option> <option value=\"word4\">word4</option> <option value=\"word5\">word5</option> <option value=\"word6\">word6</option> I have a long PHP script that I didn't write. I'd like to get a simple text list of all the unique variables from the script -- all variables within the script that begin with $, such as $_ADMIN $query $category $user $id $result, etc..... Any ideas how a PHP dabbler can go about this? I did a PHPFreaks search, but didn't find a thread on this. Thank you! Hi all.
i am trying to use php to include a javascript onto different pages, and then "sort of " pass it a var.
The bulk of the code will be in an included footer php file.
The var will be set in the main page.
i have it working as follows: by just using echo 3 times.. the 1st with the first part of the script, the 2nd is the variable, and the 3rd is the rest of the script.
The same endcode.php file needs to also be used for pages that wont have a var set, and wont be using the script - hense the isset.
<!-- mainPage.php --> <?php $sion_gallery_id = '450'; ?> <?php include(endcode.php); ?> <!-- endcode.php --> <?php if (isset($sion_gallery_id)) {echo "start of javascript.......album/"; echo $sion_gallery_id; echo"/end of script"; } else { echo "var not on set";} ?> Hello all , here is another problem of my project. I need to create a textarea , drop down list and submit button . At first , I can type whatever I want in the textarea , but for certain part I can just choose the word I want from drop down list and click submit , then the word will appear in the textarea as my next word . But I have no idea how to make this works , is there any simple example for this function ? Thanks for any help provided . Any ideas on how to extract text from html like this into multiple variables? Code: [Select] <li class="even" style="padding-top:1.25em"><label for="job_title">Title</label><div>Expatriate Tax Director</div></li> <li class="odd"><label for="job_contract_type">Contract type</label><div>Permanent</div></li> <li class="even"><label for="job_market_sector">Market sector</label><div><a href="/en/candidate/market_sectors/1.html">Accountancy / Auditing / Tax</a></div></li> <li class="odd"><label for="job_country">Country</label><div><a href="/en/candidate/countries/GB.html">United Kingdom <img src='/images/flags/GB.png'/></a></div></li> <li class="even"><label for="job_location">Location</label><div>Reading</div></li> <li class="odd"><label for="job_min_salary">Salary</label><div>120.00 - 120.00 United Kingdom Pounds/Month <li class="even"><label for="job_description">Description</label><div>Expat Tax Director <br/>Circa 120k - UK - Reading <br/> <br/>Our client is seeking experienced tax professional to undertake this central role. This position has evolved due to the firm expanding. The firm now has an immediate need for a very experienced person to direct the team. The ideal individual will have experience in advising International organisations with international tax, cost & risk assessment as well as reorganisations of processes and systems for the management of cross border employees. Business Development skills and good Client Management are essential. <br/>Attractions: <br/>- Combination of HNWI, Corporate Expat Programmes and International Partnerships <br/>- Managing a skilled and established team <br/>- Working within a successful and profitable office <br/>- Central London location <br/></div></li> <li class="odd"><label for="job_expires_on">Expires on</label><div>February 28, 2013</div></li> <li class="even"><label for="job_ideal_candidate">Ideal candidate</label><div>Expatriate Tax</div></li> </ul></div></div><div class="warning">An EU passport or work permit is required for this position. Applicants without one of these will be rejected automatically.</div> For example: I am using this code: Code: [Select] $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData; and it displays: Code: [Select] Bob 2 Which I am reading from my newuser.txt file! Which corresponds to the username bob, and he has the ID of 2. Now I want to make that linkable like this: Code: [Select] <a href=.?act=Profile&id=$IDFROMTEXTFILE(2)>$NAMEFROMTEXTFILE(BOB)</a> this is possible? If so, Thanks! It's been a while since I've dealt with text files and currently I am unable to write the contents of a variable to a text file, only the literal is being written. Should I be de-referencing or is this even possible? Also the problem is compounded by the fact that i also want to write the contents of a class display function into the text file. Code: [Select] $IP = $_SERVER['REMOTE_ADDR']; $DATE = date("Y-m-d"); $TIME = date("H:i:s"); $NameOfSender = "BLABLABLABALLA"; $email = $fieldnm_3; // use their addy instead of yours $subject = 'ikwerkthuis.be inloggegevens introductie film'; // change subject $text = 'Beste $NameOfSender, Welkom bij ikwerkthuis.be. Hieronder vind U de logingevens voor het bekijken van de introductiefilm: Adres: http://ikwerkthuis.be/index.php/introductie Gebruikersnaam: introductie Paswoord: film2012 %DataOfForm% Wij nemen spoedig contact met u op. Met vriendelijke groeten, Het ikwerkthuis.be team IP: $IP Date: $Date Time: $Time'; // change text mail($email, $subject, $text, 'From: '.$emailadd.''); // send another one out header("Location:$success_page_name"); } ?> ARRAY Example scaled down to two (renamed example only) fields $data = array( "field1" => "Text within quotes processes OK", "field2" => "Text within quotes processes OK" );
The frustating thing has been trying to figure out how to $text1 = $db_field['sampletext1']; $text2 = $db_field['sampletext2']; I have tried: $data = array( "field1" => $text1, "field2" => $text2 ); *** (AND) *** $data = array( "field1 => '$text1', "field2 => '$text2' );
But neither approach works, even though the text in both $data = array( "field1 => "text1", "field2 => "text2" ); I also tried using strval but that did not work.
So how on earth to get the (actual) text from $text1 and
It is probably something simple, so maybe I don't know Thanks for any enlightenent. -FreakingOUT
Edited January 28, 2019 by FreakingOUT (If this is a regex question and should be moved, I apologize.. wasn't sure since I don't know the answer) If my $description is the following, how would I strip away all the stuff before the list and after it and keep only the contents of the ul?: random text.. blah blah blah.. more text.. blah blah list item 1 list item 2 list item 3 random text.. blah blah blah.. more text.. blah blah Hi all, Weird one: I am re-working a site for a client. Their old site currently grabs text from a DB and somehow automatically puts it into a <ul>. The only thing to signify a <li> is a linebreak. So if I entered: Item 1 Item 2 Item 3 into the database, they would come out looking like: Item1 Item 2 Item 3 on the site. Anyone know of a way to recreate this? An example of this in action is he http://www.postureperfection.com.au/Chairs/Amore_Chair/p/495/ (please remember - I am redesigning the site!) Thanks heaps! I have a form where I have inserted 7 pre-populated relational lists. All of the information is pulling correctly from the databases, but when it posts, it's posting the value "ids" instead of the chosen text. The files a www.kcwell.com/gcc_form.php and www.kcwell.com/gccsuccess_form.php How do I set up a query to obtain the data that I need? Help! Hi guys, basically here pull out the data from database then creating taxt field automatically and submit into anther table. everything works fine but data not inserting in to the table. could you guys check my code please? <?php $con = mysql_connect("localhost","root",""); mysql_select_db("uni", $con)or trigger_error('MySQL error: ' . mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM course") or trigger_error('MySQL error: ' . mysql_error()); echo '<select name ="cid[]">'; while($row = mysql_fetch_array($result)) { echo '<option value="' . $row['CourseID'] . '">'. $row['CourseID'] .'</option>'; } echo '</select>'; //------------------ ?> <?php if(!empty($_POST["submit"])) { $value = empty($_POST['question']) ? 0 : $_POST['question']; ?> <form name="form1" method="post" action="result.php"> <?php for($i=0;$i<$value;$i++) { echo 'Question NO: <input type="text" name="qno[]" size="2" maxlength="2" class="style10"> Enter Marks: <input type="text" name="marks[]" size="3" maxlength="3" class="style10"><br>'; } ?> <label> <br /> <br /> <input type="submit" name="Submit" value="Submit" class="style10"> </label> </form> <?php } else{ ?> <form method="POST" action="#"> <label> <span class="style10">Enter the Number of Question</span> <input name="question" type="text" class="style10" size="2" maxlength="2"> </label> <input name="submit" type="submit" class="style10" value="Submit"> </form> <?php }?> result.php <?php $con = mysql_connect("localhost","root","") or die('Could not connect: ' . mysql_error()); mysql_select_db("uni",$con) or die('Could not connect: ' . mysql_error()); foreach ($_POST['cid'] as $c) {$cid [] = $c;} foreach($_POST['qno'] as $q){$qno[] = $q;} foreach($_POST['marks'] as $m){$marks[] = $m;} $ct = 0; for($i=0;$i<count($qno);$i++) { $sql="INSERT INTO examquesion (CourseID,QuesionNo,MarksAllocated) VALUES('$cid[$i]','$qno[$i]','$marks[$i]')"; mysql_query($sql,$con) or die('Error: ' . mysql_error()); $ct++; } echo "$ct record(s) added"; mysql_close($con) ?> Hi, I'm new to PHP/MySQL and need some help getting my query to work for my selection list: The selection list is built with: <form action='processformmissing.php' method='POST'> <fieldset> <legend>Choose Department</legend> <select name='depart'> <option value=''></option> <?php while ($row = mysqli_fetch_array($result)) { extract($row); echo "<option value='$department'>$department</option>\n"; } ?> </select> <p><input type='submit' value='Select Department' /></p> </fieldset> </form> The data is then sent to: $depart = $_POST['depart']; $deptlike = "%".$depart."%"; echo "<p>$depart</p>"; echo "<p>$deptlike</p>"; $query = "SELECT * FROM lifecerts INNER JOIN employees ON lifecerts.cid = employees.cid WHERE department LIKE '$deptlike' ORDER BY employees.name"; Hitting the submit button from my selection list form seems to be working fine because when I echo my data ($depart and $deptlike) it is giving me the correct value, but the query doesn't give me any results. However, if my post data comes from a text box instead of a selection list, my query works fine. Any thoughts on what I'm doing wrong??? Many thanks! does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; |