PHP - Showing Different Contents In One Template
Hi guys!
Could you give me advice about this issue: index.php Code: [Select] <?php $page = $_GET['page']; if ($page == NULL) { $page = "main"; } ?> <div>Header</div> <div> <?php require("view/$page.php");?> </div> <div>Footer</div> main.php Code: [Select] <?php require "func.php"; ?> <form method="post" action="view/add.php"> <input type="text" name="from" value=""><br /> <input type="submit" value="Add"> </form> add.php Code: [Select] <?php require "../func.php"; $from = $_POST['from']; $a = add($from); echo $a; ?> func.php Code: [Select] <?php function add($a) { $c = $a+100; return $c; } ?>I need output result (echo $a) in new windows (target= _blank) and output must be same like with main.php. In other words content of add.php output in index.php This code is just simplified of real code. Thank you in advice Similar TutorialsI need to set up a method for a user to be able to upload a pdf that should then be readable in the browser but I want to make it work a bit like Google Patents. Basically the rest of the users shouldn't be able to grab the content. It should be read only so as not to be passed around for free. It looks like Google is scanning each page and then running it through a reader to get the text. It then also seems to find the position of all the text so it can search the image for particular words and highlight them(cool js). Any way has anyone seen a php/ js version of this concept that I can get some hints from? Actually any language is ok if it works well. Tx I am pretty new to PHP and am trying to create a simple (so I assumed) page to takes data from one html page(works fine) and updates a MYSQL Database. I am getting no error message, but the connect string down to the end of the body section is showing up as plain text in my browser window. I do not know how to correct this. I have tried using two different types of connect strings and have verified my names from the HTML page are the same as listed within the php page. Suggestions on what I need to look for to correct would be great. I have looked online, but so far all I am getting is how to connect, or how to create a comment, so I thought I would try here. Thank you for any assistance I may get!! - Amy - Code: [Select] <body><font color="006600"> <div style="background-color:#f9f9dd;"> <fieldset> <h1>Asset Entry Results</h1> <?php // create short variable names $tag=$_POST['tag']; $serial=$_POST['serial']; $category=$_POST['category']; $status=$_POST['status']; $branch=$_POST['branch']; $comments=$_POST['comments']; if (!$tag || !$serial || !$category || !$status || !$branch) { echo "You have not entered all the required details.<br />" ."Please go back and try again."; exit; } if (!get_magic_quotes_gpc()) { $tag = addslashes($tag); $serial = addslashes($serial); $category = addslashes($category); $status = addslashes($status); $branch = addslashes($branch); $comments = addslashes($comments); } //@ $db = new mysqli('localhost', 'id', 'pw', 'inventory'); $db = DBI->connect("dbi:mysql:inventory:localhost","id","pw") or die("couldnt connect to database"); $query = "insert into assets values ('".$serial."', '".$tag."', '".$branch."', '".$status."', '".$category."', '".$comments."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." asset inserted into Inventory."; } else { echo "An error has occurred. The item was not added."; } $db->close(); ?> </fieldset> </div> </body> I used this code $limit = 120; if (strlen($summary) > $limit) $summary = substr($summary, 0, strrpos(substr($summary, 0, $limit), ' . . .')); This code ok in English Language it counts letters fine but it is not work fine if I insert Arabic text. It counts Arabic encoding characters. Hi all
So I'm back to being a php newbie after not touching the stuff for years....and straight back to being pretty sure I'm just incredibly stupid.
I want to grab the contents of a url onto a string so that I can search the string and use the contents. I think this should work:
<?php $homepage = file_get_contents('http://www.example.com/'); echo "Homepage = " . $homepage; ?>But it doesn't. What am I doing wrong, or could there be an issue with my server that means it's not able to perform this maybe? (It's working fine for everything so far) Or is there another way of achieving this? Thanks!! I want to parse some tiny lines from a webpage. I have few questions: 1. What is faster and better: cURL or file_get_contents? 2. Is it better to run preg_match commands form every line I want OR first get a shorter part (e.g. between <head> tag) then running preg_match for the lines? 3. Actually, I need to load the whole page before parsing. Is there a way to stop loading the whole page. For example, when I want something between <head> tag; stop loading <body>? Thank you in advance! I have this script below that makes an XML which displays the contents of a directory which contains image files. After running the .php, the XML output looks like this: Code: [Select] <gallery> <content src="./uploaded/images/Desert.jpg"/> <content src="./uploaded/images/Penguins.jpg"/> <content src="./uploaded/images/tux.png"/> <content src="./uploaded/images/Jellyfish.jpg"/> <content src="./uploaded/images/Chrysanthemum.jpg"/> <content src="./uploaded/images/Tulips.jpg"/> <content src="./uploaded/images/Koala.jpg"/> </gallery> I would like the output to be like: Code: [Select] <gallery> <photos> <photo> <content src="./uploaded/images/Desert.jpg"/> </photo> <photo> <content src="./uploaded/images/Penguins.jpg"/> </photo> <photo> <content src="./uploaded/images/tux.png"/> </photo> <photo> <content src="./uploaded/images/Jellyfish.jpg"/> </photo> <photo> <content src="./uploaded/images/Chrysanthemum.jpg"/> </photo> <photo> <content src="./uploaded/images/Tulips.jpg"/> </photo> <photo> <content src="./uploaded/images/Koala.jpg"/> </photo> </photos> </gallery> Here is the script: Code: [Select] <?php $path_to_image_dir = "./uploaded/images"; // path to your image directory $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <gallery> </gallery> XML; $xml_generator = new SimpleXMLElement($xml_string); if ( $handle = opendir( $path_to_image_dir ) ) { while (false !== ($file = readdir($handle))) { if ( is_file($path_to_image_dir.'/'.$file) ) { $image = $xml_generator->addChild('content'); $image->addattribute('src', $path_to_image_dir.'/'.$file); } } closedir($handle); } header("Content-Type: text/xml"); echo $xml_generator->asXML(); ?> Hello friends, if i have the following $path = "http://*site*.com"; why can't i write the following $ORGtext= file_get_contents('$path'); it works only if i write $ORGtext= file_get_contents('http://*site*.com'); but i want to put $path instead of the url at file_get_contents is it possible and if yes then how ? thank you Hello there, Using PHP, what's the best way of replacing the contents between different HTML 5 element tags on the fly? Some of the elements I'm looking to change can be found below. I have looked into the possibility of using Regular Expressions, but have found lots of material on the internet that try to prevent you from using such a method for parsing HTML due to speed and other HTML code related issues. Any help, example code, and ideas on this is greatly appreciated. Code: [Select] <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Some Title</title> </head> <body> <div>Replace contents of div tag.</div> <p class="someClass">Replace contents of p tag.</p> <table> <tr> <th>Static Table Heading 1</th> <th>Static Table Heading 2</th> <th>Static Table Heading 3</th> </tr> <tr> <td>Replace Table Data 1 Contents</td> <td>Replace Table Data 2 Contents</td> <td>Replace Table Data 3 Contents</td> </tr> <tr> <td>Replace Table Data 4 Contents</td> <td>Replace Table Data 5 Contents</td> <td>Replace Table Data 6 Contents</td> </tr> </table> </body> </html> Hey there, I have an image gallery running on my website right now and I want to give the site admins access to add/delete the images from the different gallery directories. But to be honest I'm totally lost on how to do it lol I know my way around PHP but I've never had to code something to pull up the dir contents with an option to delete the files. I've found scandir which will get the contents of a dir and unlink which deletes a file but I have no clue how to get them to work together, anyone got any ideas or a different function if I'm looking in the wrong direction with those functions. Any help would be much appreciated. Thank you! eg http://www.xxxxxxx.com/index.php?action=viewarti&artid=5 How can I write the content of this link into file. Hi guys. This is my first post here, so excuse me if i am posting this in the wrong forums. I am making a website, and having a huge problem. The script is used for orders of different services. And i am using sessions to store the information through serveral pages. But my problem is that on my final page, where the script sends an email with i can not get it to view the contents of one session. I am using the same session on a different page and it works like a charm. When i try debugging the session it won't print the contents, so i am guessing something is very wrong? My code of the page is bellow, let me know if you need anything else: http://pastebin.com/YHh3bGWS Please help me Hello all, I've run in to a very strange problem that I've never seen before. in my "config.php" file I have something like this... <?php // the URL of the script. NO trailing slash. $xconfig['url'] = $r['cfg_site_url']; // the site name $xconfig['title'] = $r['cfg_site_title']; // the YouTube user name to populate the site with. $xconfig['youtube_user'] = $r['cfg_site_youtube']; // the video to show on the homepage $xconfig['homepage_video'] = $r['cfg_homepage_video']; ?> and in my index.php page, I have <?php include "config.php"; ?> but, also in index.php, I have this <?php echo $xconfig['title'] ; ?> but it won't echo! None of the values in $xconfig[] output anything. I've even done put this in index.php <?php var_dump($xconfig); exit; ?> and that shows the array with the contents I expected. So, why does the array have the correct contents, but will not echo? Thanks a ton! How does a web server, with a database connect to the emails it receives? How does the web server get the contents of the emails it receives so I can parse it? Thanks Hi This is something used in CPUs Logical shift right I have a string $bin = "10011101"; // result should be "01001110" the function is function LogicalShiftRight($bin) { for($x = 7; $x == 0; $x--) { echo $x; $bin[$x+1] = $bin[$x]; } $bin[0] = 0; return $bin; } cant get the loop to work backwords. This is an 8 bit shift right putting a zero at the highest bit. Hello, I have a simply query that will if a simple two different things: Code: [Select] $cssyn = mysql_query("SELECT `12` FROM `12345` WHERE `abc` = '$_SESSION[number]'"); $cssy = mysql_fetch_row($cssyn); if($cssy[0] == "YES") { echo "Yes"; } else { echo "No"; } The YES or NO result is stipulated earlier on so thats not the problem. But basically before I added the if statement simply would have echoed a table with all the rows etc from another query. However I would like to give the user a choice between echoeing the results into one table or a neater two. I have separated the code for the table and the queries into two separate files but say if I use: file_get_contents then it just prints the HTML and doesnt actually populate it will the queried parts. Nor if I use something like include() then it wont echo anything, which it wouldnt unless called so what I am asking is: Is there a way to get EVERYTHING from the file if the answer is YES or the other file if NO. I have made a file explorer for my site so i can upload files, delete them and rename them. Everythings working fine except when i want to delete a folder. I realise you cant use ftp_delete, coz' that only works for files. I have tried rmdir, and even though I am getting no errors, it seems to do nothing :s So what is the best way to delete a folder and its contents using PHP FTP commands? Thanks guys What is the proper way to output the contents of a class? (We will assume that Getters and Setters are evil...) Let's say I have the following class... class FormHandler2 { // Define Variables. private $myFormArray; // Constructor. public function __construct($param){ $this->myFormArray = $param; } } ...and I want to be able to output its contents either via a variable dump OR by printing something to the screen. How would I do that? TomTees Hello all, I'm sure something like this has been brought up before but I think it's quite a unique problem and I didn't get anywhere searching... so here's my first post. Yay. Right, so, basically I have a database table that looks like this: Code: [Select] +----------+-------+ | name | value | +----------+-------+ | settingA | true | | settingB | false | | settingC | false | +----------+-------+ And I have been racking my brains trying to figure out how to get that data into an array formatted like so: Code: [Select] Array ( [settingA] => true [settingB] => false [settingC] => false ) The best I have been able to do, using nested foreach() statements, is this: Code: [Select] Array ( [0] => Array ( [name] => settingA [value] => true ) [1] => Array ( [name] => settingB [value] => false ) [2] => Array ( [name] => settingC [value] => false ) ) ...which is not very practical, or at least it isn't for what I want to do. Any ideas on what the best method might be for achieving this? I am using ADOdb Lite but even an example using PHP's native MySQL functions could help me figure out what to do. Thanks! I have 2 pages...1 one that has something like 500 checkboxes that list all of the active users in a database. When any number of checkboxes are selected it passes the variables from the checkboxes to the next page, asking for confirmation.
Right now I have the 2nd page displaying numbers for the people, but doesn't display the correct entries.
The code is below, hopefully it helps:
if(isset($_POST['Update'])) //if the update button was pressed { if (isset($_POST['Player_number'])) //checks to see if any checkboxes are selected { //$Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items echo $Player_number; ?> <input type="hidden" name="<?PHP $Player_number; ?>" value="<?PHP $Player_number; ?>"> $Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items $result = mysql_query("SELECT * FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error()); while ($row = mysql_fetch_array($result)) //while ($row = mysql_fetch_assoc($result)) { // here is your data echo "FName: ".$row['Player_First_Name']; echo "lName: ".$row['Player_Last_Name']; echo "email: ".$row['player_email']; } foreach($_POST['Player_number'] as $row) { $result = mysql_query("SELECT `Player_First_Name`,`Player_Last_Name`,`player_email`, `Player_number` FROM `players` WHERE `Player_number` = '$Player_number' ORDER BY Player_Last_Name") or die(mysql_error()); $Player_number = IMPLODE(',',$_POST['Player_number']); //putting the comma in between the array items while($rows=mysql_fetch_array($result)) { echo "Player Number: ".$Player_number; //echo "pNumber: ".$row; //echo $rows['Player_First_Name']; ?> <tr bgcolor='<?PHP echo $bkcolor; ?>'> <td width = '20%' height="20"><div align="center"><input type="hidden" name="Player_number[]" value="<?php echo $row; ?>"></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_First_Name']; ?></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['Player_Last_Name']; ?></div></td> <td width= '20%' headers="20"><div align="center"><?php echo $rows['player_email']; ?></div></td> <?PHP }//close of the while loop }//close of the foreach loop }//close of if (isset($_POST['Player_number'])) } //close of (isset($_POST['Update']
Hey, I need a bit of help replacing some variables in a string. I know its done with preg_replace. Here is the string: Code: [Select] Header 1 <|header 2|> header 3 <b>header 4</b> I would like to get ONLY <|header 2|> from the above string. But "header 2" is variable so please its useless if the preg_replace isn't flexible to find whatever word is in there regardless. Thanks you. |