PHP - Getting Rid Of Unwanted Info
I am parsing an rss feed from my flickr photostream using this:-
<?php $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=49466419@N05&lang=en-us&format=rss_200"; $rss = simplexml_load_file($url); if($rss) { echo '<h1>'.$rss->channel->title.'</h1>'; echo '<li>'.$rss->channel->pubDate.'</li>'; $items = $rss->channel->item; foreach($items as $item) { $title = $item->title; $link = $item->link; $published_on = $item->pubDate; $description = $item->description; echo '<h3><a href="'.$link.'">'.$title.'</a></h3>'; echo '<span>('.$published_on.')</span>'; echo '<p>'.$description.'</p>'; } } ?>which gives me this as the description for each image:- public 'description' => string ' <p><a href="http://www.flickr.com/people/alfthomas/">Alf Thomas</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/alfthomas/14064465890/" title="harlaw_12"> <img src="http://farm6.staticflickr.com/5077/14064465890_83c02ecec6_m.jpg" width="240" height="110" alt="harlaw_12" /> </a> </p> <p>A view of Harlaw Reservoir.</p>' (length=338)What I actually want is the photo (linked back) without the "Alf Thomas posted a photo" bit, does anyone have any idea how I would go about cloning that bit out? Edited by foucquet, 31 May 2014 - 08:14 AM. Similar TutorialsHi, I have the following script: <?PHP $match = '/.*?\\d+.*?(\\d+)(\\s+)/is' ; $dbh = new PDO('mysql:host=localhost;dbname=xxxx', 'xxxx', 'xxxx') ; $result = $dbh->query("SELECT companyName, invoiceAddress FROM detail_sheets WHERE area = 'Germany'") ; $codes = array() ; $names = array() ; $c0s = array() ; $c1s = array() ; $c2s = array() ; $c3s = array() ; $c4s = array() ; $c5s = array() ; $c6s = array() ; $c7s = array() ; $c8s = array() ; $c9s = array() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if(preg_match($match, $row['invoiceAddress'], $matches)) { $codes[] = substr($matches[1], 0, 1) ; $names[] = $row['companyName'] ; //array_push($found, substr($matches[1], 0, 1), $row['companyName']) ; } } $i = 0 ; foreach($codes as $current) { $currentName = $names[$i] ; $result = $dbh->prepare("SELECT (sum(partbaskets.total) - sum(pourbaskets.total)) AS Margin FROM partbaskets, pourbaskets, enquiries, jobs WHERE partbaskets.enquiryRef = enquiries.id AND pourbaskets.enquiryRef = enquiries.id AND jobs.enquiryRef = enquiries.id AND jobs.status != 'Cancelled' AND enquiries.enqState != 'Inert' AND enquiries.companyName = ? ") ; $result->bindParam(1, $currentName, PDO::PARAM_STR) ; $result->execute() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if($current == 0 && $row['Margin']) array_push($c0s, $row['Margin']) ; if($current == 1 && $row['Margin']) array_push($c1s, $row['Margin']) ; if($current == 2 && $row['Margin']) array_push($c2s, $row['Margin']) ; if($current == 3 && $row['Margin']) array_push($c3s, $row['Margin']) ; if($current == 4 && $row['Margin']) array_push($c4s, $row['Margin']) ; if($current == 5 && $row['Margin']) array_push($c5s, $row['Margin']) ; if($current == 6 && $row['Margin']) array_push($c6s, $row['Margin']) ; if($current == 7 && $row['Margin']) array_push($c7s, $row['Margin']) ; if($current == 8 && $row['Margin']) array_push($c8s, $row['Margin']) ; if($current == 9 && $row['Margin']) array_push($c9s, $row['Margin']) ; } $result = NULL ; $i++ ; } echo "<table><tr><td>Area</td><td>Margin</td></tr>" ; echo "<tr><td>Area 0</td><td>" . array_sum($c0s) . "</td></tr>" ; echo "<tr><td>Area 1</td><td>" . array_sum($c1s) . "</td></tr>" ; echo "<tr><td>Area 2</td><td>" . array_sum($c2s) . "</td></tr>" ; echo "<tr><td>Area 3</td><td>" . array_sum($c3s) . "</td></tr>" ; echo "<tr><td>Area 4</td><td>" . array_sum($c4s) . "</td></tr>" ; echo "<tr><td>Area 5</td><td>" . array_sum($c5s) . "</td></tr>" ; echo "<tr><td>Area 6</td><td>" . array_sum($c6s) . "</td></tr>" ; echo "<tr><td>Area 7</td><td>" . array_sum($c7s) . "</td></tr>" ; echo "<tr><td>Area 8</td><td>" . array_sum($c8s) . "</td></tr>" ; echo "<tr><td>Area 9</td><td>" . array_sum($c9s) . "</td></tr></table>" ; ?> But what is happening is that the Margin is being multiplied by the number of rows in partbaskets (which is the same amount of rows in pourbaskets). So for instance, if there is one part per job for a companyName, there is no problem and I get the correct margin. But, if there is say 4 parts for one of the jobs, then the margin for that job will be multiplied by 4, which is wrong. I have tried using GROUP but it didn't help. Can someone please give me the missing link in my SQL statement? Hello all, A simple question: I have a HTML application from which a php script is executed. 'GET' method is used and no form is submitted. I was wondering if there is a way to prevent users from run this php script directly in the browser. Thank you all for your suggestions, Mamer Hi everyone, I don't know whether this is a PHP or MySql problem, but I think it is the former. The following code queries the database correctly, (and before you ask, there are no duplicate database entries), but the output duplicates every row. e.g., hammer (jpg image) hammer hammer (jpg image) hammer saw (jpg image) saw saw (jpg image) saw screwdriver (jpg image) screwdriver screwdriver (jpg image) screwdriver and so on. I cannot see why the code causes the row to repeat. Code: [Select] <?php session_start(); if (isset($_SESSION['id'])) { // Put stored session variables into local php variable $id = $_SESSION['id']; $userId = $_SESSION['userId']; $userGroup = $_SESSION['userGroup']; $managerId = $_SESSION['managerId']; } include_once("demo_conn.php"); $sql = mysql_query("SELECT * FROM users WHERE id='$id'"); while($row = mysql_fetch_array($sql)) { // Get member data into a session variable $egroup = $row["egroup"]; session_register('egroup'); $_SESSION['egroup'] = $egroup; } $query = mysql_query("SELECT topics.url_big, topics.url_small, topics.title, topics.$egroup, quiz.passState, quiz.userDate FROM topics INNER JOIN quiz ON (topics.managerId = quiz.managerId) WHERE topics.$egroup = 1 ORDER BY title ASC"); while ($row1 = mysql_fetch_array($query)) { echo "<a href='../../wood/wood_tool_images/{$row1['url_big']}' target='_blank'><img src='../../wood/wood_tool_images/{$row1['url_small']}' /><br />\n"; echo "{$row1['title']} <br />\n"; } ?> Hi guys,
I am using this code to open and close a pop up window, but as soon as i click the close button this
http://localhost/popup.php?random=&button=
automatically adds in the url, Please tell me what is wrong with the script
<script type="text/javascript"> $(document).ready(function(){ $('a.popup-window').click(function(){ var popupBox = $(this).attr('href'); $(popupBox).fadeIn(400); var popMargTop = ($(popupBox).height() + 24)/2; var popMargLeft = ($(popupBox).width() + 24)/2; $(popupBox).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); $('body').append('<div id="mask"></div>'); $('#mask').fadeIn(400); return false; }); $('button.close,#mask').live('click', function(){ $('#mask,.popupInfo').fadeOut(400,function(){ $('#mask').remove(); }); return false; }); }); $(document).keyup(function(e){ if(e.keyCode ==27){ $('#mask,.popupInfo, #popup-box').fadeOut(400); return false; } }); </script> </head> <body> <a href="#popup-box" class="popup-window">Click</a> <div id="popup-box" class="popupInfo"> <form> <label>ANYTHING</label></br> <input type="text" name="random"/></br> <button type="submit" name="button" class ="close">close</button> </form> </div> </body> </html> Edited by chauhanRohit, 27 June 2014 - 09:46 AM. Code: [Select] <?php # This script does get included into the document create_new_tag_from.php if(isset($_POST['tag_name_submit'])){ $tag_name_submit = $_POST['tag_name_submit']; } if(!empty($_POST['tag_name'])){ $tag_name = strip_tags($_POST['tag_name']); } if(!empty($_POST['tag_description'])){ $tag_description = strip_tags($_POST['tag_description']); } if(isset($tag_name_submit)){ # The Validation of User Entered Data # Do validate for solely alphabetic characters with ctype_alpha # ctype_alpha($tag_name) && if(ctype_alpha($tag_description)){ $tag_name = strtolower($tag_name); $tag_description = strtolower($tag_description); # The Insertion Into the Database $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); # Do research if SQL query has to be modified into a PHP comform query $sql_query = sprintf( "set @newid = convert( ( select max(convert( (substring(tag_id, 2)) , unsigned integer))+1 from tags), char(10) ); set @newid = if(length(@newid) = 1, concat('0', @newid), @newid); set @newid = concat('c', @newid); INSERT INTO tags (tag_id, tag_name, tag_description, added_by_user_id, creation_date, last_edited) VALUES (@newid, '%s', '%s', 7, now(), '0')", mysqli_real_escape_string($db_connect, $tag_name), mysqli_real_escape_string($db_connect, $tag_description) ); $sql_query_run = mysqli_multi_query($db_connect, $sql_query); # Print Test to See If It Works echo "works_ "; echo $tag_name . "_ "; echo $tag_description . "_ "; } else { # End of the Validation echo "The entered data must be in alphabetic characters."; } } ?> Here is the form: Code: [Select] <?php include_once('../../header.php'); include_once('../../model/contribution/create_new_tag_script.php'); ?> <form action="" method="post"> <input type="text" name="tag_name" value="" /> <textarea maxlength="60" type="text" name="tag_description" value=""></textarea> <input type="submit" name="tag_name_submit" value="Submit the New Tag" /> </form> <?php include_once('../../footer.php'); ?> By the script as given above the conditional check will skip to the error message. Though I have to say that ctype_alpha does return TRUE when I do try it with "tag_name" which is entered data from the input field, while the other is from the textarea. I simply cannot see the reason for the returned FALSE. Hi Everyone, I am writing a PHP script to allow some of my site members to add links to their site. The script is setup to use a supplied link to an image, then make that image a clickable link which in turns opens that webpage. Here is my code: Code: [Select] <?php if($_POST['formsubmit'] == "Submit") { $varLink = $_POST['Link']; $varImage = $_POST['Image']; $varDescription = $_POST['Description']; } $filea = "temp.tmp"; $fileb = "original.txt"; $filec = "newfile.txt"; $fa=fopen($filea,'w'); /* Open Temp File and Write $_POST data */ if($fa) { fwrite($fa,"<a href='$varLink'><img src='$varImage'></a><br>$varDescription<br><br>\n"); fclose($fa); } $fa=fopen($filea,'r'); /* Open Temp File and Read Contents */ if($fa) { $bufa=fgets($fa); fclose($fa); } $fc=fopen($filec,'w'); /* Open New File to merge new and old Links */ if($fc) { fwrite($fc, $bufa); /* Write Newest Link First */ } $fb=fopen($fileb,'r'); /* Open Original file and Read it */ if($fb) { while(!feof($fb)) { /* Loop through complete old file and write to new file */ $bufb=fgets($fb); fwrite($fc, $bufb); } } fclose($fb); fclose($fc); unlink('original.txt'); /* Delete Original File */ unlink('temp.tmp'); /* Delete Temp File */ rename('newfile.txt', 'original.txt'); /* Rename New File to the Old Filename */ ?> NOTE The above code has been 'expanded' in my troubleshooting efforts... (i.e. I wrote the first write to file code, executed it and checked the file contents manually, then the 2nd step, etc....) so my final code will be shorter. The problem I am having,.... when i write the 1st file 'temp.tmp', I get the expected data in the file (below). <a href='http://www.somesite.com'><img src='http://www.somesite.com/pic.jpg'></a><br>Description of site<br><br> However, when I read the temp.tmp and original.txt files and write it to the newfile.txt (to merge it all together) the expected data is there but with an extra entry after each 'good' entry (below): <a href='http://www.somesite.com'><img src='http://www.somesite.com/pic.jpg'></a><br>Description of site<br><br> <a href=''><img src=''></a><br><br><br> I don't understand why i am getting the extra entry '<a href=''><img src=''></a><br><br><br>' in the file. Can anyone shed some light on this? My head is sore from banging it on the wall! I have an exercise for school that I have to work out. My teacher is letting us figure it out ourselves, but I've ran into some troubles: - We have to make 2 files: sescook1.php and sescook2.php. - We have to make a form for the user to fill out their name and favorite color (in sescook1.php). - We have to check the input (whether there is input or no). If there's isn't any input, we have to echo 'Please fill out __' (in sescook1.php) - We have to store the name in a session variable and the color in a cookievariable (in sescook1.php) - If both fields are filled in, we ave to show a link 'go to the next page' (where 'next page' is an URL to sescook2.php). - All info has to be shown in sescook2.php (Entered name: __, Entered color: ___) - You have a link 'Go back to previous page' (where 'previous page' is an URL to sescook1.php) My code: Quote <?php session_start(); function checkContent() { if($_POST["name"] == "") echo "Please enter your name"; elseif($_POST["favcolor"]) echo "Please enter your favorite color"; else echo "Go to <a href='http://localhost/webadv1011/PHPCookiesSessies/sescook2.php'>next page"; } ?> <form name="color" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onsubmit="<?php checkContent(); ?>"> <p>Name: <input type="text" name="naam" /></p> <p>Favourite color: <input type="text" name="favcolor" /></p> <p><input type="submit" name="submit" value="send" /></p> </form> This is the code I got so far. My problem is that the page refreshes itself after it does the checkContent function. I'm also not sure how I save my name in a session variable and the color in a cookie variable (and pass them to the next page as well!). We haven't learned anything on cookies and sessions except our own trial and error and things I found on the internet. Unfortunately, I can't really find lots of useful info (most people refer to Ajax, but we can only use php), or I'm looking in the wrong place. Thanks for your help in advance! When I try to run the code below with Code: [Select] if ( $user->uid ) it works just dandy. But if I use Code: [Select] if ( !$user->uid ) it puts the number one a little bit below my truncated paragraph. It only started doing this after I put the Code: [Select] $login = print("Log in to see full article!");. It worked normally (besides the fact that it didn't say log in to see full article) And for description, I have 400 words of Lorem Ipsum, but you guys dont need to see that so I put elipses. Code: [Select] <head> <?php // this signifies how to truncate function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit if(strlen($string) <= $limit) return $string; // is $break present between $limit and the end of the string? if(false !== ($breakpoint = strpos($string, $break, $limit))) { if($breakpoint < strlen($string) - 1) { $string = substr($string, 0, $breakpoint) . $pad; } } return $string; } ?> <title>truncate test</title> </head> <body> <?php $description = 'Lorem. ipsum dolor sit amet...'; // This makes it so it only applies to non logged in users if ( !$user->uid ) { //Replace 'XXX' with your number (Probably 500) $description = myTruncate($description, xxx); $login = print("Log in to see full article!"); } echo "<p>$description</p>"; echo "<p>$login</p>"; ?> This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=328141.0 I have 2 files; Newfault.php and thankyou.php 1) Data is entered into a form in Newfault.php 2) The data from this form is retieved in thankyou.php and is then inserted into a table called "Calls" Problem: My entered record is being added to my database OK, but it is also adding a blank record for some reason and I can't work out why. Can anyone help? This is for my uni assignment. Thanks, Ladykudos I'm having a problem with some php code that allows you to edit a text file. No matter what file it loads, it always adds four horizontal tabs and two spaces to the end of the text. I've attached the code to this post. If anyone can help me with this, it would be greatly appreciated. Cindy Very simple question. I have a table with courses and a table with students registered for those courses. I have a page where I can change the course name. What I want to do is, when changing the course name in the course table, I want all students in the students table who are already registered for that course to have that course name updated as well in the student table. I'm currently using a field cid to update the courses in the course table however, the student table doesn't have a cid field rather a cname ( course name) which I want to use to update the fields in the student table. Is it possible to use Code: [Select] <a href=\"editcourse.php?cid=" for more than one field of info? i.e transfer the cid + cname and so you can use $_GET[cid]"; and $_GET[cname]"; ? Something like this maybe ( dont know how the code will go) "editcourse.php?cid=&cname=" ? Do I have the right idea for how to go about this? Hey guys, It's been awhile since I've coded in PHP and I can not for the life of me remember how to do this. Say I have http://www.example.com/search.php?name=joe&size=small What the PHP code to grab the ?name=joe&size=small part? thanks hello, i am transferring the post number from a forum page, to a non-forum page via url variables.. how do i stop someone editing the url variable and viewing the posts concerned? i thought i could possibly use cookies/or a kind of auto-post form.. please help if you can.. just what to google would be appreciated For some odd reason, my MySQL array is not returning any data. I echo'd the query and it is correct, I looked at the database and that row is in there, but when I print_r the array, nothing. Here is the code. $infoquery = "SELECT * FROM '$endotype' WHERE ID = '$typeid' ORDER BY ID DESC LIMIT 1"; $info = mysql_query($infoquery); echo $infoquery; $infoout = mysql_fetch_array($info); print_r($infoout); Its a very simple query and its driving me nuts. Hi all, Ive latly coded a option for my website which allowes users to send money. Ive finished coding it but when I press the submit button the money dont get sent to the other user it just puts it in the url bar. Example: http://********.com/newbank.php?touser=Test&sendmoney=1000000000&sendmoney=Send+Money! <?php session_start(); include ("includes/db_connect.php"); include ("includes/functions.php"); logincheck(); $username = $_SESSION['username']; // Fetch users stuff.. $fetch_u = mysql_query("SELECT * FROM users WHERE username='$username'") or die (mysql_error()); $fetch_users = mysql_fetch_object($fetch_u); // Fetch bank stuff.. $fetch_b = mysql_query("SELECT * FROM bank") or die (mysql_error()); $fetch_bank = mysql_fetch_object($fetch_b); // User sending money.. if ($_POST['sendmoney']){ $send_money = strip_tags($_POST['ammount']); $to_user = strip_tags($_POST['touser']); if (!$to_user){ echo ("You must enter a username."); }elseif ($to_user){ $user_real = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username = '$to_user'")) or die (mysql_error()); if ($user_real == 0){ echo ("No such user!"); }elseif ($user_real != 0){ if ($send_money > "0"){ if ($send_money == 0 || !$send_money || ereg('[^0-9]',$send_money)){ echo ("You carnt send that type of money"); }elseif ($send_amount != 0 || $send_amount || !ereg('[^0-9]',$send_amount)){ if ($send_money > $fetch->money){ echo ("You havent got that much money"); }elseif ($send_money <= $fetch->money){ // Try sending money to yourself if (strtolower($to_user) == strtolower($username)){ echo ("You cannot send money to yourself"); }elseif (strtolower($to_user) != strtolower($username)){ $to_person = mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$to_user'")); $otherusercash = $send_money; $otheruser = $to_user->money + $otherusercash; mysql_query("UPDATE users SET money = money-$send_money WHERE username='$username'"); mysql_query("UPDATE users SET money = '$otheruser' WHERE username='$to_person'"); $time = gmdate('Y-m-d h:i:s'); mysql_query("INSERT INTO `transfers` ( `id` , `to` , `from` , `amount` , `date` ) VALUES ('', '$to_person', '$username', '$send_amount', '$time')") or die (mysql_error()); echo "Money Sent!"; echo "<meta http-equiv=\"refresh\" content=\"0;URL=newbank.php\">"; } } } } } } } ?> <html> <head> <link rel="stylesheet" href="includes/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> <title>Running-Mafia || Send Money</title> </head> <body> <form action='' name='form1'> <table width='50%' border='1' bordercolor='#000000' align='center' bgcolor='#808080' cellpadding='0' cellspacing='0' style='border-collapse: collapse'> <tr> <td colspan='2' background='header.jpg' align='center'>Send Money</td> </tr> <tr> <td> Username: </td> <td> <input type='text' name='touser' class='infobg' id='touser'> </td> </tr> <tr> <td> Ammout: </td> <td> <input name="sendmoney" class='infobg' type="text" id="send_money"> </td> </tr> <tr> <td> </td> <td> <input class="button" name="sendmoney" type="submit" id="sendmoney" value="Send Money!"> </td> </tr> </table> </form> </body> </html> Anyone see why its not sending the money? Thanks. In my script, users login with their Username & Password. However, I'd like to be able to echo the email address used on their account.
I've tried adding the email to the session I'm not having much luck... Here's a piece of the login code(untouched); $username = $_POST['name']; $passwd = $_POST['passwd']; $query = "SELECT name,passwd FROM users WHERE CONCAT('0x', hex(passwd)) = '{$salt}'"; $result = mysql_query($query); $login_ok = false; if(mysql_num_rows($result) > 0) { $login_ok = true; } if($login_ok) { $row = mysql_fetch_array($result, MYSQL_NUM); $_SESSION['user'] = $row;I've also tried messing around with this piece below in a few different ways but still nothing. <?php echo htmlentities($_SESSION['user']['email'], ENT_QUOTES, 'UTF-8'); ?>Any help is greatly appreciated.. Hello Guys... I'm new to php & mySQL... I need help... Need something to know... please help me... I'm using ubuntu 11.10, Aptana Studio 3, xampp 1.7.7. Also i'm using windows 7, notepad++ & wamp. When I visit "localhost" on my firefox. I saw a xampp or wamp welcome page. The name of the file is "index.php". 1. I need to know can I delete this file ? Bcoz i'm working on another file but it's the same file name. 2. When I upload my site on host like hostgator. How do i edit my live site? And preview it. 3. How do i store my post on database ? Like fb status update, blogger post or forum post I wanna write a site that i can post something without using html <p></p>. The main problem when i need to post something then everytime I need to edit the source code. Example:<p>some text here</p>. I don't wanna edit source everytime. Another Ques: Is Aptana Studio and notepad++ enough to write a site or I need another tool ? Any book suggestion ? please guys help me i'm new to php & mySQL.. When I get a hit on my site I like to see where they came from and if they came from a search engine what keywords they used. So here is the refer info: http://www.google.com/search?q=dog+training&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a I guess I need to split everything into an array or something. Has anyone done this? Any Ideas? Thank you! let's say I have 100,000 users on my forum i want to cache there PROFILE INFO (About me) in .php files which is easy/etc but would that be more space than 100k rows in a db table, or 100k .php files? just wondering, prob a stupid question but atm I cache some lottery info and some other stuff, but that's only 1 .php it would be dumb to cache info and have 100k .php's for each user ID right? or maybe story it all in 1 .php? would be a HUGE Filesize? rather just keep the data in MYSQL right? |