PHP - How To Skip Over Images When Splitting Text
hi, how is everybody doing? i hope well, i have a problem with some php code. i am trying to split some text in two parts once they have been split, they are display, but sometimes the php code break the source code of the page such as images and instead of the image i get the source code like this
Quote add-plugins-paintnet-1.2-800x800 3857cff9733e6a.jpg" style="border-width: 1px; border-color: #000000; border-style: solid; margin: 4px auto 5px; display: block;" /> i have tried for about 2 days now to fix it and i haven't been able to, so any help or guidence would be greatly appreciated. this is the code that i am currently using, i have tried to change the variable in the $findTag but nothing seems to work Code: [Select] <? php $article =$this->article_>text; $countchars=strlen($article); $divide=$countchars/2; $firstpart=substr($article,0,$divide); $secondpart=substr($article,$divide); //i keep changing the <p /> variable to <img /> and $image and many others but nothing seems to work $findTag = strpos($secondpart, "<p /> "); $var = $divide + $findTag $firstpart = substr($article, 0, $var); $secondpart = substr($article, $var); ?> thanks Similar TutorialsI have a text field that contains the following (example text used): 1 2 3 4 5 6 As you can see the first few are split by a single space, with the last few numbers split by a double space. My aim is to put each of these numbers into a table in a MYSQL database. But I'm having trouble breaking them up. Hi Guys, does anyone know how split a text into groups depending on how many words are in the text e.g $text = "If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. "; I want a maximium of 5 words in each group, so the above text will be split as such $text1 = 'If you are new to'; $text2 = 'PHP and want to get'; $text3 = 'some idea of how it '; $text4 = 'works, try the introductory tutorial.'; But if I want a maximium of 10 words in each group, so the above text will then be split like this $text1 = 'If you are new to PHP and want to get'; $text2 = 'some idea of how it works, try the introductory tutorial.'; $text3 = ''; $text4 = ''; Is this possible? Please any help will be much appreciated thanks Hello, I have a variable that holds a piece of text that looks something like this: "world,blue,big". Is there anyway to split the text into the separate words as an array, and remove the commas? Code: [Select] $text_to_split = "world,blue,big"; $splitArray = array(); //Do some kind of php function that splits text\\ echo splitArray[0]; // world echo splitArray[1]; //blue echo splitArray[2]; //big Would appreciate it, thanks Hello, I have a long list of webpage addresses like this which extends below the fold / the bottom of a user's screen: Webpage 1 Webpage 2 Webpage 3 Webpage 4 Webpage 5 Webpage 6 Webpage 7 Webpage 8 Webpage 9 Webpage 10 Webpage 11 etc... I want to take this long list of words and split them into columns so that the reader never has to scroll down. Please can you tell me the best way of going about this? (should I just design for a specific screen resolution? - if so which screen resolution should I design for?). Many thanks, Stu Hello , I've this code its skip the weekend ,and I've a table for special events has field datetime. What I need when its come across this datetime skip it like it does with the weekend. there's the code Code: [Select] <?php$database_date = '2011-08-12, 07:00:00'; //this comes from your database, $updated_time = strtotime('+' . hoursLeft($database_date,7,16,24) . ' hours',strtotime($database_date)); //Handle the date:$new_date = date('m-d-Y, H:i:s',$updated_time); //this is when the email should be sent.echo date('m-d-Y, H:i:s',strtotime($database_date)) . '<br />' . $new_date . '<-- you should be emailing at this time!'; //just echo's it to the screen.function hoursLeft($time,$work_starts,$work_ends,$time_to_email,$skip_weekends = true) { //this function handles the count of how many hours you need to fulfill your task. $parts = explode(' ',$time); //split the time off of the date. list($hour, $minute, $second) = explode(':',$parts[1]); //get the hours, minutes, seconds. if($minute == 0) { //if the minutes is over 0, then return a full hour for it $hours = $work_ends - $hour; } else { //otherwise, take into account that this isn't a full hour. $hours = ($work_ends - 1) - $hour; } $day_count = 0; //original day count is 0; for($i = $work_ends,$count = $hours; $count <= $time_to_email; $i++) { //Start the increment at 16, the count at the current hours, keep the count below 25, increment on each loop. if($i > 24) { //if the increment is over 24, reset it to 0. $i = 0; ++$day_count; //increment day_count when i goes over 24 hour limit. if($skip_weekends == true) { //if you want to skip weekends $day = date('l',strtotime("+ {$day_count} days",strtotime($time))); //get the full text of the current day the hours are pointing to. if(in_array($day, array('Saturday','Sunday'))) { //and current day is in the weekend. $hours += 24; //add 24 hours to the count. continue; //restart loop, before any counting takes place. } } } if($i > $work_starts && $i <= $work_ends) { //if the increment is between 7 and 16, add to the count, which will break the loop at 24. $count += 1; } $hours += 1; //add to the hours, the loop breaks at a count of 24, which will give us the total hours to add to the updated_time above. } return $hours; //return hours}?> OUTPUT: Code: [Select] 08-12-2011, 07:00:0008-16-2011, 14:00:00<-- you should be emailing at this time!9 hours for Friday:9 hours for Monday:7 hours for Tuesday:= 24 hours. I'm waiting for your replys.. This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319516.0 hello, how would i skip the first line on inserting the csv? Code: [Select] <?php include '../style.php'; if(isset($_POST['submit'])) { $filename=$_POST['filename']; $handle = fopen("$filename", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into goaliestats(id,name,gp,w,so,gaa,date) values(NULL,'$data[0]','$data[2]','$data[8]','$data[26]','$data[18]','$data[28]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; } else { print "<form method='post'>"; print "Type file name to import:<br>"; print "<input type='file' name='filename' size='20'><br>"; print "<input type='submit' name='submit' value='submit'></form>"; } ?> How do I skip to the next index in a foreach loop? I've tried the following: Code: [Select] foreach($c as $val){ if(1==1){ next; } echo "HI" } In the code above it still echos HI How do I fix this? Hi wondered if someone could help me i have this code: if (isset($data['product_image'])) { foreach ($data['product_image'] as $image) { $image = $image.".jpg"; $image = str_replace (" ", "", $image); $filename = '/home/purchase/public_html/fancydresscostumesonline.co.uk/image/'. $image; if (file_exists($filename)) { $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'"); } else { $this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = 'no_image.jpg'"); } } } This part of the code adds a jpg at the end of the product_image additional images so in my csv the 10 columns which have additional numbers for example in my csv it has: say 00532 so this code adds 00532.jpg once imported the the next part which is the else statement no_image.jpg adds a no_image.jpg but instead of it inserting a no_image.jpg for all the blank cells i would like it to SKIP the blank cells for the additional images which is product_image so if no number in the cell it SKIPS it. but have no clue how to do it. Hope someone can help Regards, Aaron I have a basicc form that takes users info and when they submit it it show on a new web page in the proper order. I need to know how do I skip a blank field. This form takes a users First, Middle, and Last name but many times they leave the middle name blank so I would want to skip this field from showing up when the form is posted. Here is what I have for the basic php script ..Would like to know how to skip a field if it is left blank on the form. echo $_POST["First"], print "."; ?><?php echo $_POST["Middle"], print "."; ?><?php echo $_POST["Last"], print "."; ?><?php echo $_POST["Persona1"], print ".";<br /> Hey all, first post to this site. I'm somewhat new to PHP, so bear with me - this might be an easy question, it might not be. Just looking for a little help. Basically, I have a query which takes commands from a form through AJAX (day, time, time1). The query executes a wildcard on a table named sip_data, searches for linked $id (so if $id=3, for example in multiple tables, it spits out the $name, $zip in a div). Here's the code: Code: [Select] <?php $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $dbname = ""; //Connect to MySQL Server $link = mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $id = $_GET['id']; $name = $_GET['name']; $zip = $_GET['zip']; $server_url = $_GET['server_url']; $day = $_GET['day']; $time = $_GET['time']; $time1 = $_GET['time1']; // Escape User Input to help prevent SQL Injection $id = mysql_real_escape_string($id); $name = mysql_real_escape_string($name); $zip = mysql_real_escape_string($zip); $server_url = mysql_real_escape_string($server_url); $day = mysql_real_escape_string($day); $time = mysql_real_escape_string($time); $time1 = mysql_real_escape_string($time1); //build query $query = "SELECT * FROM $day,sip_data WHERE $day.id=sip_data.id AND $day$time<=>$day$time1 ORDER BY zip ASC"; //Execute query $qry_result = mysql_query($query) or die(('No Results')); //Build Result String while($row = mysql_fetch_array($qry_result)) { echo "<table id=query_result align=left>"; echo "<tr>"; if($zip = $row[zip]); echo "<th><b>$row[zip]</b></th>"; echo "</tr>"; echo "<tr>"; echo "<td><a href=$row[server_url] rel=ajaxDiv>$row[name]</a></td>"; echo "</tr>"; echo "</table>"; } echo $display_string; ?> Basically, my issue with this is that some of the results within the sip_data DB will have zip codes that repeat. The current code prints out each results with the zip code and name - here's an image of a sample result: What I would like to do is avoid repeating the zip code and just group the results under each zip code, kinda like this: 55408 55412 55423 --------- ------------ ---------- example example example example example example Any help would be greatly appreciated. I feel like I'm so close to the answer, but just need a little guidance. Who knows, I might be way off. Thanks in advance! Hi All, i am trying to Generate a image dynamically. Up to here i am able to do it . But when i give any echo statement with this its not working.. Here is my code pls help me in this <?php // Create a 55x30 image $im = imagecreatetruecolor(79, 79); $unknow = imagecolorallocate($im, 0, 255, 255); $white = imagecolorallocate($im, 255, 255, 255); // Draw a white rectangle imagefilledrectangle($im, 4, 4, 75, 25, $unknow); imagefilledrectangle($im, 4, 29, 75, 50, $unknow); imagefilledrectangle($im, 4, 54, 75, 75, $unknow); // Save the image echo 'hi hello'; header("Content-type: image/png"); //imagepng($im, './imagefilledrectangle.png'); imagepng($im); imagedestroy($im); ?> Thanks in advance. When i upload photos and the name of the photo i would like to be able to overlay a portion of the original photo with another image already in the site directory, and also add the photos name over the top of the overlayed image, i may have explained this in a confusing way so i have attached an example. Is this something that can be done using something like GD or imagick, if so could someone please give me a good place to start. Heya guys! What's up? OK here's my problem: I got a variable, $var1, which is to have values like "groan,100,200,350,50" I need to know how to split this $var1 into $split1, $split2, $split3, $split4, $split5, where $split1 = "groan"; $split2 = "100"; $split3 = "200"; $split4 = "350"; $split5 = "50"; Thanks in advance people! P.S. In my case I am going to use some of the values for calculations. So I don't think that its easy with arrays, which are difficult for me to understand . P.S.S. When I am retrieving data from the database, many variables like $var1 that need to be split are being extracted. I hope that you understand. Thanks and Regards, Thauwa http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/get_hit_list?user_id=100000952273457&target_id=100000556624340&level=300&auth_key=cb07c7575b38df48d82dd53619385faa884db5a2 When going to this URL, it gives entries between <entry> and </entry>, what I am trying to do, is collect the <user_id> ONLY if the <amount> is over a certain value. Any ideas to how I could do this (I am a complete PHP noob). All help is appreciated The sample string is KmSO4 Every upper case alphabet should be identified and splitted until another upper case alphabet comes. the string should be splitted so that output array looks like this Array ( => Km [1] => S [2]=>O4 ) can any one help regarding this issue? Hi guys Say for example I have a text field with value 20/10/2011 how do I define it so that $x=20, $y=10 and $z=2011 so that I have three variables Thanks I could use some suggestions on how to break up my HTML and PHP. Currently I have a file called "payment_form.php" It looks like this... Code: [Select] <body> <?php // HANDLE FORM. if (isset($_POST['submitted'])){ // Handle Form. // Determine if any errors. if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... // Do not return to Payment Form!!! exit(); } } ?> <!-- HTML PAYMENT FORM --> <form id="payment" action="" method="post"> <fieldset> <legend>Billing Details</legend> <ol> <!-- First Name --> <li> <label for="firstName">First Name:</label> <input id="firstName" name="firstName" class="text" type="text" maxlength="20" value="<?php echo $firstName; ?>" /> <?php if (!empty($errors['firstName'])){ echo '<span class="error">' . $errors['firstName'] . '</span>'; } ?> </li> I would like to keep the Form Validation PHP in the same file as the HTML Form so the user isn't ping-ponged between two pages if they make data entry errors. However, I am thinking it would be better to break out the Payment Processing PHP and place that in a different file. How should I do that? Maybe I could add a Redirect after this code... Code: [Select] if (empty($errors)){ // Process Payment. // PHP code to send payment to Payment Gateway... Suggestions welcome!! Thanks, Debbie I have a string like this: Code: [Select] Something,Somthing Else,"keyword1,keyword2,keyword3",Yet another I need to split that string by the ,. However, I need the data that is n the quotes to remain as one even though it has commas because it is one item. I assume I need to use preg_split and have tried some code but none of it seems to work properly. If anyone has a better method or knows how I can split this up using preg_split the help is appreciated. Okay I need a little bit of help on this as strings constantly confuse me and reading tutorials actually got me a bit more loss then before. I have developed this mod that has become pretty popular and I'm debugging it. What I have are two variables. $username (The user's username, no html markup in it) $musername (The user's username, with html markup in it) So for example: $musername = <b><u>$username</u></b> The php code above would be the equivolant to what $musername is equal to. What I need to do is create an array or two variables, whatever is easier and grab all that html markup. The first variable would be all the html or anything really before the $username variable, and the other would take all of that html after the $username variable. I need to store those html markups in either two seperate variables or an array so i can call upon it later in the script. I need this to fix a bug issue. |