-
Posts
50 -
Joined
-
Last visited
Never
Everything posted by fizix
-
Alright, I've created a preg_match expression that returns all object tags in a string. However, I now need to return all the object tags that DO NOT have a semicolon somewhere in them. Could anybody tell me why this isn't working? $test = preg_match_all('/<object(.*?)(?!\<\/object>/ims', $contents, $found); Thanks!
-
It's been a few weeks, do you still plan on posting this code? Thanks!
-
OK, I figured out a way to do it but it's pretty hacked: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <title>IMG Test</title> <link rel="stylesheet" href="./styles/default/thumbnailviewer.css" type="text/css" /> <script src="./styles/default/thumbnailviewer.js" type="text/javascript"></script> </head> <body> <?php //Two test images $content = "Image 1: <img vspace=\"0\" hspace=\"0\" border=\"0\" align=\"bottom\" src=\"/images/test.jpg\" />\nImage 2: <img vspace=\"0\" hspace=\"0\" border=\"0\" align=\"bottom\" src=\"/images/fizix_crop.ba.jpg\" />"; $src = "src=\""; $thumbnail = "./phpthumb/phpThumb.php?h=75&src="; //pattern to get links to images from image tags $pattern = '!<img.*?src="(.*?)".*?/?>!'; $img = "<img"; $frontlink = "<a href=\""; $backlink = "\" rel=\"thumbnail\" />"; $closelink = "</a />"; if (strpos($content, $img) !== false) { //put all image links in $urls preg_match_all($pattern, $content, $urls); //make array with placeholders for ($x=0;$x<count($urls[0]);$x++) { $placehold[$x]="%$x"; } //append thumbnail function to image link $newcontent = str_replace($src,$src.$thumbnail,$content); //put all thumbnail links in $thumburls preg_match_all($pattern, $newcontent, $thumburls); //remove all image tags from $content and replace with placeholders $content = str_replace($urls[0],$placehold,$content); for ($x=0;$x<count($urls[0]);$x++) { $content=str_replace($placehold[$x],$frontlink.$urls[1][$x].$backlink.$thumburls[0][$x].$closelink,$content); } } echo $content; ?> </body> </html> Any suggestions for improving this are welcome!
-
Also, if you can think of a better way to do anthing else I'm doing in this snippet, I won't be offended if you wind up completely re-writing it!
-
Ok, I've started to write some code to make all images in a string thumbnails, then wrap link tags around them to link to the full-size picture. This is what I've got so far: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <title>IMG Test</title> <link rel="stylesheet" href="./styles/default/thumbnailviewer.css" type="text/css" /> <script src="./styles/default/thumbnailviewer.js" type="text/javascript"></script> </head> <body> <?php //Two test images $content = "<img vspace=\"0\" hspace=\"0\" border=\"0\" align=\"bottom\" src=\"localhost/images/test.jpg\" />\n<img vspace=\"0\" hspace=\"0\" border=\"0\" align=\"bottom\" src=\"localhost/images/fizix_crop.ba.jpg\" />"; $src = "src=\""; $thumbnail = "./phpthumb/phpThumb.php?h=75&src="; //pattern to get links to images from image tags $pattern = '!<img.*?src="(.*?)".*?/?>!'; $img = "<img"; $frontlink = "<a href=\""; $backlink = "\" rel=\"thumbnail\">"; if (strpos($content, $img) !== false) { //put all image links in $urls preg_match_all($pattern, $content, $urls); //append thumbnail function to image link $content = str_replace($src,$src.$thumbnail,$content); //place link to full size image before thumbnail But this is where my question arrises. I want to do something like this on the next line: $content = str_replace($img,$frontlink.$urls[1][$x].$backlink.$img,$content); But I don't know how to increment $x. I need to increment $x every time str_replace replaces a string. Here's the rest of the code: } echo $content; ?> </body> </html>code]
-
[quote author=Crayon Violent link=topic=118758.msg514289#msg514289 date=1169843102] try it now [/quote] Working now. Thanks!
-
[quote author=Crayon Violent link=topic=118758.msg514132#msg514132 date=1169833575] the topic solved button only appears in certain forums. However, just for S&G, please tell us what forum your thread is in, that you are having issues with, so we can investigate and make sure the permissions are properly set. [/quote] I just posted in this forum (PHP Help) and I don't see a topic solved button. :(
-
Worked like a charm. Thanks!
-
[quote author=jesirose link=topic=124199.msg514247#msg514247 date=1169841004] Because that's what you wrote. Remove the />" before Name. [/quote] Then how do I submit an image tag as a $_POST to PHP?
-
Why, when I insert: [code]<INPUT TYPE="hidden" VALUE="<img hspace=\"0\" border=\"0\" align=\"bottom\" src=\"http://www.onr.navy.mil/media/releases/image_gallery/images/hyfly_booster_test_vehicle_captive_carry.jpg\" />" NAME="content">[/code] in an HTML page, do I see: [code]" NAME="content">[/code] on the page?
-
NVM, figured it out. Can't use default as a column name. I'm dumb...
-
Nope, now I get: [code]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='1'' at line 1[/code]
-
Alright, I'm trying to copy data from my themes table to my style table. Here is my query: [code]$query="INSERT INTO `style` SELECT 'bgred', 'bggreen', 'bgblue', 'red1', 'green1', 'blue1', 'menuback', 'highlights', 'borders', 'textcolor', 'red', 'green', 'blue', 'linkcolor' FROM 'themes' WHERE default='1';";[/code] I'm getting the following error: [code]"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''themes' WHERE default='1'' at line 1"[/code] If anybody could help me resolve this error I'd be very greatful! Thanks!
-
OK, all I want to do is match the string "%1" in regex. I've tried a million different ways but it's not working. Can anybody tell me how? Thanks!
-
Hi, I need to find font tags in a string and have done part of the work already. This is what I have so far: [code]$pattern = '\</?font[^>]*\>';[/code] However, there are 2 issues: 1. I get a "Delimiter must not be alphanumeric or backslash" error when trying to use it. 2. I also need it to IGNORE any font tags that have the word "size" in them. Can anybody help me? Thanks!
-
[quote author=taith link=topic=119380.msg488911#msg488911 date=1166627514] [code]<?php function TimeAgo($timestamp){ $current_time = time(); $difference = $current_time - $timestamp; $periods = array("minute", "hour", "day", "week", "month", "year", "decade"); $lengths = array(60, 3600, 86400, 604800, 2630880, 31570560, 315705600); for($val = sizeof($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) < 1); $val--); if($val < 0) $val = 0; $new_time = $current_time - ($difference % $lengths[$val]); $number = floor($number); if($number != 1) $periods[$val].= "s"; $text = sprintf("%d %s ", $number, $periods[$val]); if(($val >= 1) && (($current_time - $new_time) > 0)) $text .= TimeAgo($new_time); return $text; } echo TimeAgo('6435421'); ?>[/code] [/quote] This solution won't work. I still need to be able to see the seconds if the time entered is less that 24 hours ago. A good example would be how digg handles the time on their site.
-
Bump. Can anybody help me with this?
-
Ok, I've grabbed the following snippet of code off the internet to output the amount of time elapsed since the time that was passed to it: [code]<?php function TimeAgo($timestamp){ // Store the current time $current_time = time(); // Determine the difference, between the time now and the timestamp $difference = $current_time - $timestamp; // Set the periods of time $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade"); // Set the number of seconds per period $lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600); // Determine which period we should use, based on the number of seconds lapsed. // If the difference divided by the seconds is more than 1, we use that. Eg 1 year / 1 decade = 0.1, so we move on // Go from decades backwards to seconds for ($val = sizeof($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) < 1); $val--); // Ensure the script has found a match if ($val < 0) $val = 0; // Determine the minor value, to recurse through $new_time = $current_time - ($difference % $lengths[$val]); // Set the current value to be floored $number = floor($number); // If required create a plural if($number != 1) $periods[$val].= "s"; // Return text $text = sprintf("%d %s ", $number, $periods[$val]); // Ensure there is still something to recurse through, and we have not found 1 minute and 0 seconds. if (($val >= 1) && (($current_time - $new_time) > 0)){ $text .= TimeAgo($new_time); } return $text; } ?> [/code] It works really well but I'd like to change one thing. I only want it to output 2 iterations. So say I input a time that's 1 day, 1 hour, and 30 seconds from now. I only want it to tell me the 1 day and 1 hour part but to cut off the seconds. Along the same lines, if I input a time that's 1 month, 1 day, 1 hour, and 30 seconds from now, it should only output 1 month and 1 day. I hope this makes sense to everybody! Let me know if you can't understand what I'm trying to do. Thanks!
-
[quote author=mjdamato link=topic=118641.msg485009#msg485009 date=1166123941] Depends on the circumstances. You could simply create a session variable called $_SESSION['loggedin'] and set to 1 when they go through the log in script. Or, if security is an issue you may need to store the username and hashed password or a temporary key to validate on every page. [/quote] Am I right that anybody could put loggedin=1 in their cookie if they wanted? Is there a way to validate using their session ID?
-
I haven't worked with FTP in a while but try adding a trailing slash like so: [code]mkdir("artwork/".$newdir."/");[/code]
-
I think you had some things mixed around... Try this: if(!isset($_POST['business'])) { $business = stripslashes($_POST['business']); mkdir("artwork/".$business); }
-
[resolved] GD image library - one single odd image
fizix replied to BarneyJoe's topic in PHP Coding Help
That link didn't work. :-\ -
First of all: Hi everybody! Second: This may be a loaded question BUT, what is the best way to validate that a user is logged in? I'm using: [code]session_start(); $_session['username'] = "$username"; $_session['ip'] = $_SERVER['REMOTE_ADDR']; [/code] to start a session. However, how do I verify on future pages that they've logged in and have a valid session?