PHP - Merging 2 Parts Of Code
Similar TutorialsHello guys, I don't really know php but I am always been able to copy/paste it and move stuff around on my wordpress website until now. This last challenge is beyond my skills though (I am sure it will be trivial for you). So I have this code snippet to show a video duration <?php global $post; $video = cbc_get_video_data( $post ); if( $video ) { echo $video->get_human_duration(); } ?> And I have this code to show a post title if ($show_title) { $title_content .= apply_filters( 'uncode_before_body_title', '' ); $title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . get_the_title() . '</h1>'; $title_content .= uncode_post_info() . '</div>'; $title_content .= apply_filters( 'uncode_after_body_title', '' ); } I want to show the video duration right before the post title and in line with it, so inside the h1 tag. How to do that? Thanks for any help!
so I have this code..........(not in brackets sorry) <table width="410" border="1" cellspacing="0" cellpadding="0"> <tr> <td width="339" bgcolor="#999999" scope="col">EVENTS</td> </tr> <tr> <td class="afasd"><?php echo date("F",strtotime("-0 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("-0 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> <tr> <td class="adfaf"><?php echo date("F",strtotime("+1 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("+1 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> <tr> <td class="jasdfjs"><?php echo date("F",strtotime("+2 month")); ?></td> </tr> <tr> <td><?php if ($startdate == date("F",strtotime("+2 month"))){ echo "<p><a href='viewevent.php?eventid=$eventid'>$startdate - $enddate --- $event</a></p>\r\n"; }else{ echo"there are no events scheduled for this month" ;} ?></td> </tr> </table> so Only the third piece is working displaying correct things...........the other two don't display at all....... I am new to php. I have been at this for 8 hours and I am not getting anywhere. The objective is to convert the 4-file html/php application into a 1-file php application and generate exactly the same answers and look as the original. I also attached the files. Code: [Select] step1.html: <html> <head><title>STEP1</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <form action="step2.php" method="post"> ENTER INPUT1(A or B): <select name="input1"> <option>A</option> <option>B</option> </select> <input type="submit" value="ENTER"/> </form> </div></body></html> step2.php <html> <head><title>STEP2</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $choice=$_POST["input1"]; if($choice=="A") { echo "<form action='step4.php' method='post'>"; echo "<input type='hidden' name='input1' value='5'/>"; } else if($choice=="B") { echo "<form action='step3.php' method='post'>"; echo "<input type='hidden' name='input1' value='1'/>"; } else { echo "<form action='step1.html' method='post'>"; } ?> ENTER INPUT2(1-10) : <input type='text' name='input2' size='3'> <input type="submit" value="ENTER"/> </form> </div></body></html> step3.php: <html> <head><title>STEP3</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $x="1"+$_POST["input1"]; $y="1"+$_POST["input2"]; $z=(int)$x+(int)$y+2; echo "<div class='output'>OUTPUT: "; if($y<=15) { echo "$z.$y.$x";} else { echo "$x.$y.$z";} echo "</div>"; ?> <div class="note">MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div></body></html> step4.php: <html> <head><title>STEP4</title><link rel="stylesheet" type="text/css" href="steps.css" /></head> <body> <div class="block"> <?php $xf="1"+$_POST["input1"]; $xz="2"+$_POST["input2"]; $xaq=(int)$xf; $xax=(int)$xz; if($xaq>$xax) {$xaq=$xaq+33;$xax=$xax+31;} else {$xaq=$xaq+2;$xax=$xax+44;} echo "<div class='output'>OUTPUT: "; echo "$xf.$xaq.$xax.$xz"; echo "</div>"; ?> <div class="note">NOTE: MAKE SURE TO COPY/WRITE THE OUTPUT</div> <a href="step1.html">RESTART</a> </div></body></html> [attachment deleted by admin] This must be easy enough, but I'm a noob so go easy on me, please :-)
I have two pieces of code and they're working well on their own. All I need is to put these two conditions into one query.
The first one:
<?php function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'events_categories', 'mycategory1' ); } } add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' ); ?>And the second: <?php function childtheme_cat_limited_blog( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'category_name', 'mycategory2' ); } } add_action( 'pre_get_posts', 'childtheme_cat_limited_blog' ); ?>I'm sure it's a piece a cake for you guys, but I can't figure it out for the life of me, so any help would be greatly appreciated! Thank you! (My goal is here to display posts from two categories on a homepage of a Wordpress site, but to complicate things the two categories are from two different post types.) What I'm looking to do is analyze an array of coordinates and generate a convex-hull type outline of all independent polygons merged. Convex hull isn't ideal for my situation as I need the outline detailed. From: To: This is how the data is arranged (The keys are just for reference): $array['Group_01']['Polygon_01'] = array('latitude, longitude', 'latitude, longitude', 'latitude, longitude', etc.); $array['Group_01']['Polygon_02'] = array('latitude, longitude', 'latitude, longitude', 'latitude, longitude', etc.); $array['Group_01']['Polygon_03'] = array('latitude, longitude', 'latitude, longitude', 'latitude, longitude', etc.); $array['Group_02']['Polygon_01'] = array('latitude, longitude', 'latitude, longitude', 'latitude, longitude', etc.); $array['Group_02']['Polygon_02'] = array('latitude, longitude', 'latitude, longitude', 'latitude, longitude', etc.); etc. Basically in that scenario I would like to join ALL of the coordinates to form an outline in both 'Group_01' and 'Group_02' based on the polygons in 'Polygon_xx' under that group. Each outline independent of itself. So 'Group_01' would be a union of $array['Group_01']['Polygon_01'], $array['Group_01']['Polygon_02'], and $array['Group_01']['Polygon_03']. Then 'Group_02' would be a union of $array['Group_02']['Polygon_01'] and $array['Group_02']['Polygon_02']. This would output an array of something like $array['Group_01']['Unified'] and $array['Group_02']['Unified'] etc. Is this possible? Any help would be greatly appreciated. Thanks. Hi there, I am using HTML forms to post values from a data entry page. When they arrive on the second page - I have to extract them from the POST array. This is fine, but I now have to merge them somehow. When I use print_r to view the POSTed data, I see: Code: [Select] [namesUnem] => Array ( [0] => Brian [1] => Richard [2] => Sarah ) [commentsUnem] => Array ( [0] => Brian Comments here [1] => Richard Comments should be entered here [2] => Sarah's Comments were also entered here ) [namesHW] => Array ( [0] => Sally [1] => Kate [2] => William ) [commentsHW] => Array ( [0] => Sally Comments here [1] => Kate's Comments should be entered here [2] => William's' Comments were also entered here ) There are 2 more such arrays being POSTed. I would need to merge in order to see the following: Quote [Name] => Brian [Comment] => Brian Comments here [Type] => namesUnem [Name] => Richard [Comment] => Richard Comments should be entered here [Type] => namesUnem [Name] => Sarah [Comment] => Sarah's Comments were also entered here [Type] => namesUnem [Name] => Sally [Comment] => Sally Comments here [Type] => namesHW [Name] => Kate [Comment] => Kate's Comments should be entered here [Type] => namesHW [Name] => William [Comment] => William's' Comments were also entered here [Type] => namesHW Any help greatly appreciated Kindest Regards AikenD Hey! I have a bunch of text files with one line of text ex. SHS9GW34 I'm trying to write a little php script on my local machine that will take all the files and put all the different codes in the same files in this kind of format: RGDGIDSG453 EOHBDSBN453 ERGD4535355 etc etc Thanks Hello. I'm currently trying to write a code to merge two separate images together, but for the life of me I can't find anything that works. Basically what I'm trying to do is add a "marking" (cat_stripes.png) to a pet image (cat.png). In the future I also want to use this for adding items to pets and things like that. Both of the images have transparent backgrounds, so that needs to be taken into account. If you haven't got a clue what I'm talking about, look up Wajas or similar virtual pet sites to get an idea of how the markings work. I just need something simple, since I don't have a site set up yet and I'm just testing some things out for a future project. I don't have any codes at the moment, since nothing has worked so far. I'm pretty new to GD too (I'm familiar with all the basic php stuff, so don't panic), so you might need to explain some of the more advanced stuff to me. Any help with this would be really appreciated, thanks. (: $query = "SELECT Table1.*, Table2.A, Table2.B, Table2.C, Table2.D, Table2.E FROM Table1 INNER JOIN Table2 ON Table1.A = Table2.A Issue is that there are multiple matches for some instances, like so: Table1.A value = 1777 (only once since it is a UniqueID) Table2.A value = 1777 (3 records with this ID value) So I will get 3 records returned since Table1.A matches 3 records in Table2.A. I want to merge the 3 records in Table2 into 1 record and then match that with Table1 where the UniqueID is the same. Make sense? 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. I currently have a flat file user registration and login in system. I also have a simple guestbook which i didn't code myself, the guest book currently requires the user to type in there name and e-mail address to make a post. how ever i would like them to have to login and if they aren't logged in then don't display the guestbook. Live version: B50crew.co.uk Guestbook.php: Code: [Select] <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?> Login: Code: [Select] <?php // find out the domain: $domain = $_SERVER['HTTP_HOST']; // find out the path to the current file: $path = $_SERVER['SCRIPT_NAME']; $url = "http://" . $domain . $path ; extract($_POST); if($Submit){ $date = date('D d Y h:i'); $comment=eregi_replace("\r\n","*",$comment); $comment=eregi_replace("\n","*",$comment); $fp = fopen("bin/guestbook.nfo","a+"); if(!$fp) { echo 'Error: Cannot open file.'; exit; } fwrite($fp, $date."||".$name."||".$email."||".$comment."\n"); fclose($fp); } ?> <div align="center"> <h2><span class="style1">Guestbook </span><br> </h2> </div> <form name="form1" method="post" action="<?php echo $url;?>"> <label>Name <input type="text" name="name"> </label> <label>Email <input type="text" name="email"> </label> <p> </p> <p> comment<br> <textarea name="comment" cols="40" rows="10"></textarea> <br> <label> <input type="submit" name="Submit" value="Sign"> </label> <br> </p> </form> <hr> <?php $userinfo = file("cgi-bin/guestbook.nfo"); echo '<table border="0">'; foreach($userinfo as $val) { //explode that data into a new array: $data = explode("||", $val); echo '<tr><td>'.$data[0].'</td></tr>'; echo '<tr><td>'.$data[1].' Wrote:</td></tr>'; $data[3]=eregi_replace("\*","<br>",$data[3]); echo '<tr><td>'.$data[3].'</td></tr>'; echo '<tr><td>Email:'.$data[2].'<hr></td></tr>'; } echo '</table>'; ?> Session.php <?php class user { var $file_dir = ""; function start($time = 3600) { session_set_cookie_params($time , ''); session_name('afroxav-login'); session_start(); // Reset the expiration time upon page load if (isset($_COOKIE['afroxav-login'])) { setcookie('afroxav-login', $_COOKIE['afroxav-login'], time() + $time, '', 'localhost', 0, 1); } if (!isset($_SESSION['info'])) { $this->data = array('name' => 'Anonymous', 'logged' => false); } else { $this->data = $_SESSION['info']; } } function check_login() { if ($this->data['logged'] !== true) { return false; } else if ($this->data['logged'] === true) { if ($this->data['name'] !== 'Anonymous') { return true; } return false; } return false; } function login($user, $pass) { $logins_raw = @file_get_contents($this->file_dir . 'users.php'); $logins_processed = str_replace('<?php exit; ?>', '', $logins_raw); $logins_array = explode('\n', $logins_processed); foreach ($logins_array as $id => $line) { $logins[$id] = explode('|', $line); } $pass = $this->hash_pass($pass); foreach ($logins as $user_info) { if ($user_info[1] == $user) { if ($user_info[2] == $pass) { $this->update_session($user_info); return true; } } } return false; } function hash_pass($string) { return hash('sha512', $string); } function logout() { $_SESSION['info'] = array('name' => 'Anonymous', 'logged' => false); $this->data = $_SESSION['info']; return true; } function prep_reg_array($name, $pass, $email, $mod = 'false', $admin = 'false') { $id_raw = @file_get_contents($this->file_dir . 'id.php'); $id = str_replace('<?php exit; ?>', '', $id_raw); $id = $id + 1; @file_put_contents($this->file_dir . 'id.php', '<?php exit; ?>' . $id); return array($id, $name, $this->hash_pass($pass), $email, $mod, $admin); } function register($userdata) { $write = file_put_contents($this->file_dir . 'users.php', '\n' . implode('|', $userdata), FILE_APPEND); return ($write !== false) ? true : false; } function update_session($array) { $_SESSION['info'] = array( 'id' => $array[0], 'name' => $array[1], 'pass' => $array[2], 'email' => $array[3], 'mod' => $array[4], 'admin' => $array[5], 'logged' => true ); $this->data = $_SESSION['info']; } }; //html related functions //not related at all with the sessions function html_start($title) { header('Content-type: text/html'); echo "<html>\n"; echo "<head>\n"; echo "<title>\n"; echo $title; echo "</title>\n"; echo "</head>\n"; echo "<body>\n"; echo "<h1>\n"; echo $title; echo "</h1>\n"; } function html_nav() { global $user; echo "<div>\n"; echo "Navigation\n"; echo "<ul>\n"; echo "<li><a href=\"?page=home\">Home</a></li>\n"; if ($user->check_login() == true) { echo "<li><a href=\"?page=logout\">Log Out</a></li>\n"; } else { echo "<li><a href=\"?page=login\">Log In</a></li>\n"; echo "<li><a href=\"?page=register\">Register</a></li>\n"; } echo "</ul>\n"; echo "</div>\n"; } function html_end() { echo "</body>\n"; echo "</html>\n"; } ?> I have tried many solution, but nothing seems to fix this. The problem is that i put an image with transparency on top of another image, but the transparent pixels still transparent, where they should show some of the image below it. If you call it with l=100 and p=20 i would get this result http://cl.ly/566Z instead of this http://cl.ly/56OF. Here is the source code and I have attached the images: Code: [Select] <?php header('Content-type: image/png'); echo imagepng(progressbar($_GET['l'], $_GET['p'])); function progressbar($length, $percentage) { $length = round($length / 2) * 2; $percentage = min(100, max(0, $percentage)); if($length > 0) { $bar = imagecreate($length, 14); imagealphablending($bar, false); imagesavealpha($bar, true); $empty = imagecreatefrompng('Empty.png'); imagealphablending($empty, false); imagesavealpha($empty, true); $fill = imagecreatefrompng('Fill.png'); imagealphablending($fill, false); imagesavealpha($fill, true); $lempty = imagecreatefrompng('LeftEmpty.png'); imagealphablending($lempty, false); imagesavealpha($lempty, true); $lfill = imagecreatefrompng('LeftFill.png'); imagealphablending($lfill, false); imagesavealpha($lfill, true); $rempty = imagecreatefrompng('RightEmpty.png'); imagealphablending($rempty, false); imagesavealpha($rempty, true); $rfill = imagecreatefrompng('RightFill.png'); imagealphablending($rfill, false); imagesavealpha($rfill, true); $emptycaplength = min(7, $length / 2); //5 imagecopy($bar, $lempty, 0, 0, 0, 0, $emptycaplength, 14); imagecopy($bar, $rempty, $length - $emptycaplength, 0, 7 - $emptycaplength, 0, $emptycaplength, 14); if($length > 14) { imagecopyresized($bar, $empty, 7, 0, 0, 0, $length - 14, 14, 1, 14); } $filllength = round(($length * ($percentage / 100)) / 2) * 2; $fillcaplength = min(7, $filllength / 2); imagecopy($bar, $lfill, 0, 0, 0, 0, $fillcaplength, 14); imagecopy($bar, $rfill, $filllength - $fillcaplength, 0, 7 - $fillcaplength, 0, $fillcaplength, 14); if($filllength > 14) { imagecopyresized($bar, $fill, 7, 0, 0, 0, $filllength - 14, 14, 1, 14); } imagealphablending($bar, true); return $bar; } else { return false; } } ?> Hello, I want to 'join' two corresponding array values together as in the example below. $one = array('tomato', 'ham', 'bacon'); $two = array('soup', 'sandwich', 'roll'); $final=array(?) //Desired answer = (tomatosoup, hamsandwich, baconroll) Is there a php function that can do this, or a series of functions? I am aware of array_merge but this only alternates the values from what I can see. Ideally there should be a check performed that the two are the same length before completing a merge. New to this, many thanks! Hi wondering if there's a simple way to merge or update the data from one array to another . I've tried merge data but it just adds additional records rather than merging them off one common key.
The array is just simply adding a name to another array the format of both is as follows
Array 1
[0] => stdClass Object ( [name] => [market] => Football [selection] => 7051575 ) ) Array 2 Array ( [0] => stdClass Object ( [name] => Something [market] => [selection] => 7051575 ) ) There are other fields but I'm just trying to merge the name from Array two into Array one using the selection as a common key. Is there an easy command like merge or do I have to loop thru the arrays to add the data. Thanks Hi,
I'm trying to combine two images - an uploaded image and a permanent. First I try to resize them to the same dimensions. Why I resize the uploaded image to the dimensions of permanent, everything works fine. But when I do the opposite, the images just don't merge, and the output is just the permanent image with resized dimensions. Anyone knows why?
Here is my code:
<?php if( isset( $_FILES['image'] ) ){ $desired_width = 360; $desired_height = 360; $layers = array(); switch($_FILES['image']['type']){ case "image/jpeg": $source_image = imagecreatefromjpeg($_FILES['image']['tmp_name']); break; case "image/gif": $source_image = imagecreatefromgif($_FILES['image']['tmp_name']); break; case "image/png": $source_image = imagecreatefrompng($_FILES['image']['tmp_name']); break; } $frame = imagecreatefrompng("1.png"); $desired_width = imagesx($source_image); $desired_height = imagesy($source_image); $virtual_image = imagecreatetruecolor($desired_width, $desired_height); imagecopyresampled($virtual_image, $frame, 0, 0, 0, 0, $desired_width, $desired_height, 360, 360); $layers = array($source_image,$virtual_image); $image = imagecreatetruecolor($desired_width, $desired_height); // to make background transparent imagealphablending($image, false); $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127); imagefill($image, 0, 0, $transparency); imagesavealpha($image, true); imagealphablending($image, true); for ($i = 0; $i < count($layers); $i++) { imagecopy($image, $layers[$i], 0, 0, 0, 0, $desired_width, $desired_height); } imagealphablending($image, false); imagesavealpha($image, true); header('Content-type: image/png'); header('Content-Disposition: attachment; filename="new_profile.png"'); imagepng($image); } ?> Hi guys,
I wonder if you can offer any advice?
I have two user database tables that are about 70% identical. The problem is that with one of them, the phone number for each user has been cut short by two digits (it was an error on my part early on in the database design).
What I need to do is to get the values from both tables and put them into separate arrays then compare the arrays in a loop. If, say, the first five digits of the phone number in each row of the first table match one entry in the second table then update the second table with the phone number (the full length one).
I'm about puzzled about how to approach this, I've still got a lot to learn about array functions, it seems like it should be fairly simple but I'm a bit lost as to where to begin.
Any advice would be massively appreciated!
I have a database full of strings which are basically URL's with ports, so by default my strings look like: http://example.com:1234/ http://example2.com:3030/ http://example.com:9876/ http://example.com:5432/ What I am looking for is a way to separate the host from the post so the output would be something like: Host: example.com Port: 1234 Note: I once need to check one string at a time, so what I am after is something like: $string = "http://example.com:1234/"; And the result would be something like: $host (would be example.com without http://) $port (would be the port without ending /) Any help would be great Thanks for your time reasing this. Hi I want to hide the login box's of my webpage once you login. I have thought of two ways of doing it but which one would you say is better practice? 1. use a PHP if statement to echo 'Display: none on css' - when viewing source code it still shows the form but not displayed on page itself 2. use a PHP if statement around the whole <form></form> so it physically doesnt write the html if already logged in? Or if anyone has a better way it would be appreciated if you would share it? Thanks in advance Hi all,
I would like some input on database structure for a website that will sell car parts. Necessary fields a
Manufacturer
Part type (eg: exhaust, brakes, engine etc)
Part number
Description
Year & make of vehicle it fits (may need to be separate fields, I don't know, this is my main conundrum) **
Keep in mind, this is a basic example and purely hypothetical at this moment. I haven't done any coding yet.
My main roadblock at the moment is figuring out how to engineer part compatibility in conjunction with a search. Many parts fit many different vehicles. For example, part A123 could fit:
1999-2004 Jetta 2.0
1999-2004 Golf 2.0
1999-2004 Passat 1.9
In your opinion, what would be the most efficient way to store and retreive matching parts? Would I have each model as a separate row? i.e:
row 1: 2002-2004 Jetta ... part A123
row 2: 1999-2004 Golf... part A123
row 3: 1999-2004 Passat... part A123
Basically I would have many duplicate rows where only the year and vehicle model changes. This would definitely work, but would eventually lead to a very large and messy database.
There are already companies that offer a service such as this, but I am looking at looking to sell less products and secondly, in a different language. At the moment, I'm trying to figure out the best way that I could do it. Once I have an idea in mind, then I can decide whether I want to go ahead with that or use a pre-made commercial platform.
hello guys
i wand to split the 24h of a day to parts and select the time that i wand to start the 24h circle to count!
lets say
i give 2 int variables
$day_starts_to_count_from=00;
$split_day_to_parts=4;
so!
$hours_per_part = 24/$split_day_to_parts;
this gives me $hours_per_part = 6 (i split the 24h every 6hr)
how to know the part of my current hour?
lets say the system time is 15:35
how to find that im at the 3d part 12:00-18:00 if the 24h circle starts to count from 00:00
thanks in advance
|