Jump to content

Search the Community

Showing results for tags 'explode'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL








Donation Link

Found 16 results

  1. Folks, Q1. A function parameter that takes in a constant, can it always take in a variable, unless it needs a handle ? While going through the Explode function tutorial, I did not come across anything that states the 3rd parameter (explode limit) in the Explode function has to be a string or a constant. Like so: <?php //Tutorial: http://www.tizag.com/phpT/php-string-explode.php echo "Script 1"; //Using a Constant as 3rd parameter in the Explode function. Using FOR function. $phrase = "Please don't blow me to pieces."; $words = explode(" ", $phrase); print_r($words); for($i = 0; $i < count($words); $i++){ echo "Piece $i = $words[$i] <br />"; } $explode_limit = 4; $words = explode(" ", $phrase, 4); for($i = 0; $i < count($words); $i++){ echo "Limited Piece $i = $words[$i] <br />"; } print_r ($words); ?>
  2. Php Gurus, Is there a way how you could have more than one delimiter in the following functions ? explode implode Tutorials always shows one. But let us say, we need more than one. In that case, what would you do without coding separately one by one for each delimiter ? If regex then I'd like to see some code samples. Remember, a code sample would be appreciated by all present & future newbies. Explode Imagine I want to explode this: 'The "quick brown" fox jumps over the \'lazy dog\'.' To this: ' The "quick brown" fox jumps over the \'lazy dog\' . ' As you can see, we need 3 delimiters: Space " ' Now, imagine I need to implode this: " The 'quick brown' fox jumps over the \"lazy dog\" . " To this: "The 'quick brown' fox jumps over the \"lazy dog\"." As you can see the combiners are the same in this case like they were in the other case's delimiters. I don't want to be coding 3 separate snippets to use each delimiter/combiner. Hence the question. Imagine, I got millions of html files and I need to deal with millions of lines of content like the examples shown above (which was just one line each). Ok, I was about to post this now and a thought just crossed my mind. Maybe the delimiters/combiners can be placed in an array and then on each loop the delimiter/combiner can change ? But how do I call the delimiters/combiners from each array key ? Dump the array values to a variable ? Any sample would be appreciated. Saying all this, I will try myself to build 2 snippets from one of the codes from one of my previous threads but don't hold your breath and I prefer your feed-back if it's possible to do things with array like I'm pondering. @requinix, Yes, I am creating my own terminology again: Combiner/Joiner.
  3. I am having trouble with an array. Don't know to much about them. I have a form on create.php where they can choose multiple items for there trade. On the create.pro.php is where I want it to put all the checked items from create.php together separated by commas into my database. (That way I can explode them later to get them separately - correct?) create.php $stmt = $mysqli->prepare("SELECT id, owner, item_id, uses_left FROM useritems WHERE owner = ? ORDER BY item_id"); $stmt->bind_param('s', $userid); $stmt->execute(); $stmt->store_result(); $countitems = $stmt->num_rows; $stmt->bind_result($id, $owner, $item_id, $uses_left); ECHO <<<END <center> <p><a href="index.php">Home</a> | <a href="index.php?type=me">My Trades</a> | <a href="create.php">Create Trade</a> | <a href="offers.php\">My Offers</a> | <a href="search.php">Search</a></p> <b>Note:</b> Spirits can not be traded therefore will not be shown in the items below. <form action="create.pro.php" method="post"> <center><table cellspacing="0" cellpadding="0" width="800"> END; while ($stmt->fetch()){ $stmt2 = $mysqli->prepare("SELECT name, type, value, rarity, image, description, retired FROM items WHERE itemid = ? AND type != 'spirit' AND magic_num = ?"); $stmt2->bind_param('si', $item_id, $uses_left); $stmt2->execute(); $stmt2->store_result(); $stmt2->bind_result($name, $type, $value, $rarity, $image, $description, $retired); $stmt2->fetch(); $stmt2->close(); $y = $x % 5; if ($y == 0) { echo "<tr>"; } if (!empty($name)){ echo " <td> <img src=\"$baseurl/images/items/$image\"><br> <input type=\"checkbox\" name=\"use_item\" value=\"$itemid\"> <b>$name</b><br> </td> "; } if ($y == 4) { echo "</tr>"; } $x++; } $stmt->close(); echo "</table> <p align=\"center\">Include sP: <input type=\"text\" name=\"include_amount\" size=\"20\"></p> <p align=\"center\">Wishlist: <input type=\"text\" name=\"wishlist\" size=\"40\"></p> <input type=\"submit\" name=\"submit\" class=\"mybutton\" value=\"Create Trade\"></center> </form> </center>"; create.pro.php (where the form leads to - this is the page I need help with) $array = array($_POST['use_item']); $items = implode(", ", $array); $include_amount = $_POST['include_amount']; $wishlist = $_POST['wishlist']; $stmt = $mysqli->prepare("INSERT INTO trades (items, sPoints, wishlist, owner) VALUES (?, ?, ?, ?)"); $stmt->bind_param('siss', $items, $include_amount, $wishlist, $userid); $stmt->execute(); $stmt->store_result(); $stmt->fetch(); $stmt->close(); die(header("Location: index.php?note=Trade+created.")); Thanks for any help!
  4. I have used this command before and cannot remember the name or how to deploy it.. sorta like implode but different.. what it does is take an associative array and makes individual variables out of the array like this. $str = arrray("dog->catkiller", "house->placetolive:) and when applied results in the following. $dog = "catkiller"; $house = "placetolive"; Can anyone help me with this.. I need the command name and a sample of its use..
  5. I have two questions relating to each other which are regarding - both function __autoload and adding products to a class? Code for an autoload function (please see code #1), the output prints - but also gives an error message? Moreover, I also receive the notification in my php editor "class 'ooo' not found"? If I may ask a silly question I have noticed some autoload fucctions have implode and explode - how would I write one of these? The output and error: My Antonia: Willa Cather (5.99) Fatal error: Class 'ooo' not found in C:\ Code#1: <?php // we've writen this code where we need function __autoload($classname) { $filename = "./". $classname .".php"; include_once($filename); } // we've called a class *** $obj = new ooo(); ?> ------------------------------------------------------------------------------------------------------------------------------ How would I add more products to this product class? code#2: <?php class shopProduct { public $title; protected $producer = []; public $price; public function __construct($title, $producerName1, $producerName2, $price) { $this->title = $title; $this->producer[] = $producerName1; $this->producer[] = $producerName2; $this->price = $price; } public function getProducer() { return implode(' ', $this->producer); } } class ShopProductWriter { public function write ($shopProduct) { $str = "{$shopProduct ->title}: " . $shopProduct -> getProducer() . " ({$shopProduct -> price})\n"; print $str; } } $product1 = new ShopProduct("My Antonia", "Willa", "Cather", 5.99); $writer = new ShopProductWriter(); $writer -> write($product1); ?>
  6. Hi, I have a user edit page that I cannot seem to get working correctly. We recently set out to add the addition of a avatar to our page. So... We edited the code and everything is working great for everyone but me. When I press submit on the form it sends me to a internal server error page instead of preloading the current page I am on. Everything that should get updated still does the only problem is the page will not load properly afterwards. I am at a complete wall and dont know where else to look. I was able to find out that if I remove a specific block of code the the page will reload but the picture will not update. 1. Picture wont upload but page will reload. 2. Picture will upload as expected but page doesnt reload correctly. Complete page code. <?php error_reporting(0); require('includes/application_top.php'); require('includes/classes/crypto.php'); $crypto = new phpFreaksCrypto; include('includes/classes/class.formvalidation.php'); include('includes/classes/class.phpmailer.php'); if (isset($_POST['submit'])) { $my_form = new validator; $mail = new PHPMailer(); if($_POST['password'] !== ''){ if($my_form->checkEmail($_POST['email'])) { // check for good mail if ($my_form->validate_fields('firstname,lastname,email,password')) { // comma delimited list of the required form fields if ($_POST['password'] == $_POST['password2']) { $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } $salt = substr($crypto->encrypt((uniqid(mt_rand(), true))), 0, 10); $secure_password = $crypto->encrypt($salt . $crypto->encrypt($_POST['password'])); $sql = "update " . $db_prefix . "users "; $sql .= "set password = '".$secure_password."', salt = '".$salt."', firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."', email = '".$_POST['email']."', template_name = '".$_POST['template_name']."' "; $sql .= "where userID = " . $user->userID . ";"; //die($sql); mysql_query($sql) or die(mysql_error()); //set confirmation message header('Location: index.php'); } else { $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>'; } } else { $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error); $display = '<div class="responseError">' . $display . '</div><br/>'; } } else { $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>'; } } elseif ($_post['password'] == ''){ if($my_form->checkEmail($_POST['email'])) { // check for good mail $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } if ($my_form->validate_fields('firstname,lastname,email, template_name')) { // comma delimited list of the required form fields if ($_POST['password'] == '') { $sql = "update " . $db_prefix . "users "; $sql .= "set firstname = '".$_POST['firstname']."', lastname = '".$_POST['lastname']."', email = '".$_POST['email']."', template_name = '".$_POST['template_name']."' "; $sql .= "where userID = " . $user->userID . ";"; //die($sql); mysql_query($sql) or die(mysql_error()); //set confirmation message header('Location: index.php'); } else { $display = '<div class="responseError">Passwords do not match, please try again.</div><br/>'; } } else { $display = str_replace($_SESSION['email_field_name'], 'Email', $my_form->error); $display = '<div class="responseError">' . $display . '</div><br/>'; } } else { $display = '<div class="responseError">There seems to be a problem with your email address, please check.</div><br/>'; } } else { $display = '<div class="responseError">You broke all the things</div><br/>'; } } include('includes/header.php'); $sql = "select * from " . $db_prefix . "users where userID = " . $user->userID; $query = mysql_query($sql); if (mysql_num_rows($query)) { $result = mysql_fetch_array($query); $firstname = $result['firstname']; $lastname = $result['lastname']; $email = $result['email']; $template_name = $result['template_name']; } if (!empty($_POST['firstname'])) $firstname = $_POST['firstname']; if (!empty($_POST['lastname'])) $lastname = $_POST['lastname']; if (!empty($_POST['email'])) $email = $_POST['email']; if (!empty($_POST['template_name'])) $template_name = $_POST['template_name']; ?> <h1>Edit User Account Details</h1> <?php if(isset($display)) echo $display; ?> <form action="user_edit.php" method="post" name="edituser" enctype="multipart/form-data"> <fieldset> <legend style="font-weight:bold;">Enter User Details:</legend> <table cellpadding="3" cellspacing="0" border="0"> <?php if ($isGuest) { ?> <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>" readonly></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>" readonly></td></tr> <tr><td>Email:</td><td><input type="text" name="email" value="NULL" size="30" readonly></td></tr> <?php } else { ?> <tr><td>First Name:</td><td><input type="text" name="firstname" value="<?php echo $firstname; ?>"></td></tr> <tr><td>Last Name:</td><td><input type="text" name="lastname" value="<?php echo $lastname; ?>"></td></tr> <tr><td>Email:</td><td><input type="text" name="email" value="<?php echo $email; ?>" size="30"></td></tr> <?php } ?> <tr><td>Favorite Team:</td><td><?php $template =$result['template_name'];?> <select name="template_name" > <option name="template_name" value="<?php echo "$template_name"; ?>">Choose your team template</option> <option value="main">NFL</option> <option value="ARI">Cardinals</option> <option value="ATL">Falcons</option> <option value="BAL">Ravens</option> <option value="BUF">Bills</option> <option value="CAR">Panthers</option> <option value="CHI">Bears</option> <option value="CIN">Bengals</option> <option value="CLE">Browns</option> <option value="DAL">Cowboys</option> <option value="DEN">Broncos</option> <option value="DET">Lions</option> <option value="GB">Packers</option> <option value="HOU">Texans</option> <option value="IND">Colts</option> <option value="JAX">Jaguars</option> <option value="KC">Chiefs</option> <option value="MIA">Dolphins</option> <option value="MIN">Vikings</option> <option value="NE">Patriots</option> <option value="NO">Saints</option> <option value="NYG">Giants</option> <option value="NYJ">Jets</option> <option value="OAK">Raiders</option> <option value="PHI">Eagles</option> <option value="PIT">Steelers</option> <option value="SD">Chargers</option> <option value="SEA">Seahawks</option> <option value="SF">49ers</option> <option value="STL">Rams</option> <option value="TB">Buccaneers</option> <option value="TEN">Titans</option> <option value="WAS">Redskins</option> </select></td></tr> <tr><td> </td></tr> <?php if ($isGuest) { ?> <?php } else { ?> <tr><td>New Password:</td><td><input type="password" name="password"></td></tr> <tr><td>Confirm Password:</td><td><input type="password" name="password2"></td></tr> <?php } ?> <tr><td> </td></tr> <tr><td>Avatar:</td><td><input type="file" name="img" id="img" <?php if ($isGuest) { ?> disabled <?php } ?>></td></tr> <tr><td> </td><td> <?php $avatars = glob("upload/$user->userID.*"); if(!empty($avatars)) { $avatar = $avatars[0]; echo '<img style="width:20%;" src="'.$avatar.'">'; echo '<p>**Note Image must be smaller than 3MB.</p>'; echo '<input type="submit" name="submit" value="Submit"></td></tr>'; echo '</table></fieldset></form></table></fieldset>'; include('includes/footer.php'); } else { $avatar = 'upload/default.jpg'; echo '<img style="width:20%;" src="'.$avatar.'">'; echo '<p>No avatar set, please upload one.<br>Image must be smaller than 3MB.</p>'; echo '<input type="submit" name="submit" value="Submit"></td></tr>'; echo '</table></fieldset></form></table></fieldset>'; include('includes/footer.php'); } require 'includes/correctImageOrientation.php'; correctImageOrientation('upload/'); ?> If I remove this specific piece of code then I have the case where the page loads fine but picture wont upload. $allowedExts = array("gif", "jpeg", "jpg", "png"); $extension = end(explode(".", $_FILES["img"]["name"])); if ((($_FILES["img"]["type"] == "image/gif") || ($_FILES["img"]["type"] == "image/jpeg") || ($_FILES["img"]["type"] == "image/jpg") || ($_FILES["img"]["type"] == "image/pjpeg") || ($_FILES["img"]["type"] == "image/x-png") || ($_FILES["img"]["type"] == "image/png")) && ($_FILES["img"]["size"] < 3145728) && in_array($extension, $allowedExts)) { if ($_FILES["img"]["error"] <= 0) { $files = glob("upload/$user->userID.*"); foreach ($files as $file) { unlink($file); } move_uploaded_file($_FILES["img"]["tmp_name"], "upload/" . $user->userID.'.'.$extension); } } I attached the include file that I am using in case that is helpful as well. I am using php5.4 fastCGI on a godaddy server(plesk windows hosting) correctImageOrientation.php
  7. I am scrapping an xml feed with the file_get_contents() and explode() function. Some the xml nodes do not exsist; so I am getting an inconsistant array from a for() loop. What would be the best way to keep an array key, created from an explode() function; empty, if there is no corresponding xml node to be scrapped? Currently, when I use the code below; I get all the node's content (that exsisit within the xml document) at the top and then, at the bottom; I get all the empty node's content or basically a empty/blank area. What I am getting is this: pic1.jpg<br/> pic3.jpg<br/> pic5.jpg<br/> <br/> <br/> And... what I want to get is this: pic1.jpg<br/> <br/> pic3.jpg<br/> <br/> pic5.jpg<br/> Here is my XML code (syndicate.xml): <?xml version="1.0" encoding="iso-8859-1"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:enc="http://purl.oclc.org/net/rss_2.0/enc#" xmlns:ev="http://purl.org/rss/1.0/modules/event/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:admin="http://webns.net/mvcb/" > <item> <enc:enclosure resource="pic1.jpg" type="image/jpeg"/> </item> <item> </item> <item> <enc:enclosure resource="pic3.jpg" type="image/jpeg"/> </item> <item> </item> <item> <enc:enclosure resource="pic5.jpg" type="image/jpeg"/> </item> </rdf:RDF> And... here is my PHP code: <?php $rss = file_get_contents("syndicate.xml"); $img = explode("enclosure resource=\"",$rss); for($key = 0; $key < 5; $key++){ $img2 = explode("\"",$img[$key+1]); echo $img2[0]."<br/>\n"; } ?>
  8. I seem to be struggling massively with this little problem. im sure its just a little something I am missing but it has be winding me up for hours. This is the said code. <? $id = $_POST['id']; $tags = $_POST['tags']; foreach( $id as $n ) { $tags = $tags[$n]; echo '<br><br>'.$tags.'---'.$n.'<br>'; $tags = explode(", ", $tags); $num=count($tags); echo "$num<br>"; foreach( $tags as $tag ) { print "ID: ".$n." --- tag: ".$tag." <br>\n"; } } ?> It finishes one full loop through fine, separates out all of the tags and puts them with the correct id. But when it moves onto the second full loop it seems to be getting nothing out of here $tags = $tags[$n]; I have tried changing the $n for one of the id numbers to make sure it is pulling the data from the $_POST[] and it is. The following is the results I am getting. cheese, more cheese, even more cheese---409 3 ID: 409 --- tag: cheese ID: 409 --- tag: more cheese ID: 409 --- tag: even more cheese ---287 1 ID: 287 --- tag: ---288 1 ID: 288 --- tag: ---406 1 ID: 406 --- tag: ---407 1 ID: 407 --- tag: ---408 1 ID: 408 --- tag: Any help or pointers in the right direction would be a massive help. Eric
  9. $liked = explode(":", $_POST[submit]); if($liked[0] == "like"){ //Select from database where id is $liked[1] } <input type="image" src="images/arrowup.gif" name="submit" value="like:<? echo $right->id; ?>"/> Ok, so i have made a forum and i have a like function running on the comments of a post. I needed to find a way when the image was clicked it updated the database. So i experimented and came up with the solution above having it explode the value of the button to read if it was press and get the id. It works perfectly but i just want to be convinced it is safe.
  10. Hi, In a form I am adding "1278|Toyname" as a value in a drop down. This way if they select a certain toy, I can have the ID and the toy name they are referring too. I would like to post this info in my contact form and I would like to separate via the | (Pipe) and store the id "1278" in a field called id and "Toyname" in a field named toy when the form is posted. I know I have to use the explode function to seperate but I dont even know where to begin. Thank you in advance, Bill
  11. Hey guys, so i am retrieving data from my database and have called on a certain variable.. this variable is called $personality_traits and is containing a string with all the tags (honest,go getter,lazy,humble,etc..) each persons profile is showing these traits as to what is being stored per their own ID. so one individual profile would show profile 1 Traits : Happy, Organized, Honest. Brave profile 2 Traits : Quiet, Conservative, Shy, Smart profile 3 Traits : Honest, Smart, Go getter, Now my issue: i am now trying to break this variables string into parts , so that i can echo the tags individually , and create hrefs from them accordingly. When i use the explode() this works for me and separates each tag into an index inside an array while ($row = mysql_fetch_assoc($links)) { extract($row); $user_traits // data from field `user_traits` FROM `database` $traits = explode( ',' , $user_traits ); echo $user_traits; print_r($traits); Which results in; ( for 1 profile example) positive,warm,fun Array ( [0] => positive [1] => warm [2] => fun ) My Question; How can i now list all the indices in this array for each user , as if i were inputting $user_traits ? i cant just type echo $traits[0]; echo $traits[1]; echo $traits[2]; since each profile has a different amount of variables to be defined, some have only 2 traits, while others might have 4,5 or even 6. I am assuming there is a way to do this using a mysql command , but is there anyway PHP wise to solve this problem ? any ideas or suggestions would be much appreciated, this is a feature i definitely want to have showing for my users.
  12. Hey guys, So i have a small yet very simple question more so than an issue. I am trying to call a variable that is a field from a mysql database. i am using an extract() function so any field title just returns as a variable. i have a member page where i then list the member and want to have on the side of their name the year they are born. for ex. <h1> Name ( year ) </h1> So in my data field the year the person is born is given as a full string of text 1984-14-09 Y/dd/m. All i want is the year from this data and to remove the day/month. So i did some research , and i came up with the solution of using an explode(), creating an array, and then simple echoing the index of that data i want. Problem is that the array is then leaving the entire string as one index in the array, basically not doing what i wanted it to do, which was to split the string into parts, allowing me to then echo whatever part i wanted. my code: <h1><a href="#link"><? echo $member_name; ?> (<? $arr = explode(' ',trim($member_birth_date)); print_r($arr); ?>)</a></h1> end result: any suggestions as to how to get the result i am looking for ? would really appreciate any ideas or solutions thanks guys
  13. How do I put condition upon exploding a variable that outputting different values. I've got a $variable from a loop, each loop the variable has a different content(style attribute) . sample content of the variable. . array(6) { [0]=> string(17) "font-family:Arial" [1]=> string(14) "font-size:11px" [2]=> string(13) "color:#000000" [3]=> string(16) "font-weight:bold" [4]=> string(25) "text-decoration:underline" [5]=> string(0) "" } array(4) { [0]=> string(17) "font-family:Arial" [1]=> string(14) "font-size:11px" [2]=> string(13) "color:#000000" [3]=> string(0) "" } array(3) { [0]=> string(15) "padding:1px 2px" [1]=> string(12) "display:none" [2]=> string(0) "" } array(1) { [0]=> string(0) "" } array(3) { [0]=> string(15) "padding:1px 2px" [1]=> string(12) "display:none" [2]=> string(0) "" } so if i'm going to explode it $style = explode(';', $variable); so to print out put; echo $style[0]; right? But how will I going to be more specifi. Like . . $style->font-family, or $style->font-weight Then make a condition etc. .
  14. I have been getting my rear kicked on this. I want to: 1. Read directory called "uploads" for files "cat-[thispage]-[filename].jpg". 2. If file begins with "cat" and [thispage] matches the page slug of this current (WordPress) page, print image to screen. 3. Extract [filename] and split is components (which are separated by hypens) into discrete words. 4. Print discrete words (first letter capitalized) under image. 5. Provide hyperlink to page [filename]. While I'm not a great coder, I think I can do step 1 and probably 2 (although most of you would laugh at the coding). But i really need help exploding the content and then using that data. Any help would be appreciated. Thanks.
  15. Hi Guys I have the code below to explode a value split by '.' I then want to add each item to a database. $club_id=mysql_insert_id(); foreach($_POST['age'] as $value) echo $value; //explode $value to insert into allocations $allocations=explode(".",$value); //insert into allocations $number = count($allocations); for ($i=0; $i<=$number; $i++) { // store a single item number and quantity in local variables $itno = $number[$i]; $alloc = $allocations[$i]; print_r($allocations); if ($allocations[$i] <> '') { $add_allocations=mysql_query("INSERT INTO `allocations` (`club_id`,`group`) VALUES('$club_id','$alloc')") or die(mysql_error()); } } This is the error I am getting 1.3.Array ( [0] => 3 [1] => ) Array ( [0] => 3 [1] => ) Notice: Undefined offset: 2 in /home/sites/kidzlinkz.co.uk/public_html/add-link.php on line 90 Array ( [0] => 3 [1] => ) Can someone explain how I explode an array and then add those separate values to a database.
  16. I am passing user inputs from a page called add_product.php. There is a drop down menu that CONCATs two table fields to form one name ($category). After passing $category to the product_created.php page, I can break this back down into the two respective fields using explode() on but how do I create variable out of the results? Here is the snippet from add_product.php <?php //Grab the Product Category name and Bucket name from productcategory and bucket tables in DB $qry=mysql_query("SELECT CONCAT(bucket.b_name, ' : ', productcategory.name) AS category FROM productcategory, bucket, product WHERE product.category_id = productcategory.id AND productcategory.bucket_id = bucket.id", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } ?> <p>Category: <select name="category" id="category"> <?php //take the responses from the query above and show then in a drop down menu while($row=mysql_fetch_array($qry)) { echo $category = "<option value='".$row['category']."'>".$row['category']."</option>"; } ?> </select> I then pass that to product_created.php and this is what I have so far and where I am stuck: //This gets all the other information from the form $category=$_POST['category']; // Explode category variable to get bucket.b_name and productcategory.name list($b_name, $pc_name) = explode(":", $category); echo $b_name.'<br/>'; // bucket.b_name echo $pc_name.'<br/>'; // productcategory.name //the above code works and prints the separate category names onscreen $categories = array($b_name,$pc_name); print "The product category name is $pc_name"; //test two: this code works and prints just the productcategory name //Define the query to grab the product category id where pc_name equals the product category name $sql = "SELECT id FROM productcategory WHERE name = '$pc_name'"; //submit the query and capture the result $result = mysql_query($sql) or die(mysql_error()); echo $result; //find out how many rows were retrieved $numRows = mysql_num_rows($result); //current result is 0 and should be 1 if successful //this is my attempt to convert the productcategory id into a variable that can be passed back into the DB $sql_q = "SELECT id FROM productcategory WHERE name = '$pc_name'" or die(mysql_error()); $sql = mysql_fetch_array($sql_q); //above sets the category_id array //example usage: $sql['mysql_col_name'] echo $sql['category_id']; //the above prints the category_id foreach ($sql as $category_id) { //echo $category_id.'<br/>'; } //Define query to add product to DB $qry=mysql_query("INSERT INTO product(name,category_id,slug,old_price,price,description,video_url,status,date_posted)VALUES('$name','$category_id','$slug','$o_price','$price','$desc','$video','$status','$date')", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } else { echo "<br/>"; echo "Product Added Successfully"; echo "<br/>"; } I know some of this is redundant but I am trying to teach myself how to solve this and this was the best way for me to learn. I feel like I am really close, but that I have gone round and round at this point and have just confused myself. I understand that there may be other issues with my code as it is written, but I really need to focus on resolving this first. Any help, advise, teaching, would be most appreciated.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.