|
Stupid newbie question here. Is there anything inherently wrong with the below statement, or do I need to include more of a context?code:
Is the problem in the syntax or is it something in my logic? It only outputs the "unable to insert geocode" with no specific error to work off of. J Crewl fucked around with this message at 01:26 on Mar 31, 2008 |
# ? Mar 31, 2008 01:20 |
|
|
# ? May 15, 2024 03:49 |
|
That code is hard to read. Why don't you escape your variables before constructing your query string?
|
# ? Mar 31, 2008 01:53 |
|
I would either: A) Use a database abstraction layer with prepared/parametrized queries so you don't have to do the escaping manually or B) Break the string concatenation on to another line and assigned it to a variable with some line breaks/formatting around the . operator.
|
# ? Mar 31, 2008 06:56 |
|
J Crewl posted:Stupid newbie question here. Is there anything inherently wrong with the below statement, or do I need to include more of a context? When you have a problem like this, you want to know exactly what query you're sending to the database. If you have that, you can put it into the DB shell manually and the DB will helpfully spit out an error that hopefully tells you what's wrong. So you take the query, stick it in a variable (perhaps $query), print that variable out, and then run the query on that variable. To wit: code:
|
# ? Mar 31, 2008 07:26 |
|
I'm trying to put together a text comparison tool, that will compare two strings (more than likely containing largish volumes of fulltext), and show the different, something like Wikipedia's diff functionality. Doing a simple character-by-character comparison will not work, because the first "new" character in a string will push all the others forward, causing almost everything after that point to be highlighted. Tokenising the string seems to be the way forward, but I can't work out a good way of comparing that doesn't "match" completely unrelated words later on in the text. Is there an accepted way of doing this, or am I going to need to invent some new kind of wheel?
|
# ? Mar 31, 2008 08:37 |
|
Wikipedia is opensource, why not just look at the subroutines that handle diff straight from the horse's mouth?
|
# ? Mar 31, 2008 10:45 |
|
Or just use exec() or something to run diff directly (assuming your host is running Linux). diff is a pretty clever program, I wouldn't want to be re-inventing that unless I absolutely needed to.
|
# ? Mar 31, 2008 10:54 |
|
I'm back, this time header() is giving me hell()php:<?php header('Content-type: image/jpeg');?> <html> <body> <?php //functions.inc contains displayPictureTable() include("functions.inc"); //displayPictureTable works correctly up until picture output displayPictureTable(sheds, gable); ?> </body> </html> My function displayPictureTable() works as it should as this all currently sits. It outputs my two test echos, and then attempts to output the picture I have designated but instead of pretty colors, I only get gibberish: code:
1) No header(), gibberish. 2) Put header() in the wrong spot, error message and gibberish 3) [Where I am now] I have header() in what I believed to be the correct location, am getting no error messages (E_ALL), but I'm still not getting a picture. I'm certain this is another stupid mistake (hopefully) common amongst those of us new to php, but I just can't pinpoint what the hell is going wrong here
|
# ? Mar 31, 2008 20:31 |
|
Uh, you're outputting text instead of an image. Get rid of that html nonsense.
|
# ? Mar 31, 2008 20:51 |
|
duz posted:Uh, you're outputting text instead of an image. Get rid of that html nonsense. or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page.
|
# ? Mar 31, 2008 20:54 |
|
MrEnigma posted:or move the header right before it. One other piece of advice, usually you want your functions to always return data, instead of printing it out. And then do a print/echo/whatever on on the function on your page. You can't send headers after outputting content.
|
# ? Mar 31, 2008 21:00 |
|
duz posted:You can't send headers after outputting content. True, but getting rid of my "html nonsense" changes nothing as well: php:<?php header('Content-type: image/jpeg'); include("functions.inc"); displayPictureTable(sheds, gable); ?>
|
# ? Mar 31, 2008 21:11 |
|
That's because you're still outputting text instead of the image your header is telling the browser to expect.
|
# ? Mar 31, 2008 21:12 |
Foolio882 posted:True, but getting rid of my "html nonsense" changes nothing as well: What exactly does displayPictureTable spit out? You can't output any text or html with that header set.
|
|
# ? Mar 31, 2008 21:15 |
|
Foolio882 posted:True, but getting rid of my "html nonsense" changes nothing as well: You clearly have some fundamental misunderstandings here. What are you trying to accomplish? What does displayPictureTable output? By specifying a content-type of image/jpeg, you are telling the browser that the entire document you are producing is a jpeg image. The only output should be binary image information, such as that outputted by gd's image creation functions. You can't simply spit the binary contents of an image from a gd function into the middle of an html document and expect an image to appear.
|
# ? Mar 31, 2008 21:21 |
|
fletcher posted:What exactly does displayPictureTable spit out? You can't output any text or html with that header set. Oh dear god I think I'm hosed, as the function name suggests, this is supposed to be outputting a picture table and it's loaded with required html. Is there any way to mix html and php to output a table of pictures? I'd like to avoid iterating through the directory to display them as html pictures, as I need the displayed pictures to be thumbnail links to fullsize pictures. Something like this would work, but be a complete and total pain in the rear end: php:<? $directory = opendir($picPath); while($fileName = readdir($directory)) { $dirArray[] = $fileName; } //Here display $picPath/thumbs/$dirArray[1,2,...n] as links to $picPath/$dirArray[1,2,...n] ?> This is going to suck.
|
# ? Mar 31, 2008 21:29 |
Foolio882 posted:Is there any way to mix html and php to output a table of pictures? Like this? code:
|
|
# ? Mar 31, 2008 21:35 |
|
fletcher posted:
But that's what I am trying to avoid, having seperate thumbnails. Here's the ultimate goal: 1) A potential customer comes to our website, and is interested in a Shed, Deck, or Gazebo, and would like to see some of our recent projects. 2) They somehow navigate to the "Sheds" section of recent projects, and want to see, for example, Gable style sheds that we have built. 3) Some time before this, someone has put a whole bunch of pictures into ./images/sheds/gable 4) On recentprojects/sheds/gable.php (Or whatever it may be, I don't care) this potential customer will see a table (looks aside, that's not my job) of thumbnails for every picture in ./images/sheds/gable/ 5) Each thumbnail is a link to a full size picture opening in a new window. 6) And then we somehow get another building to stand upright (Call it a gazebo), photograph it, throw it into ./images/gazebos and it's a new addition to recentprojects/gazebos.php (Just sitting there pretty at the end of the line, nothing fancy) I can do this all day long (and in fact did, as proof of concept) with seperate directories for thumbs and full size images, but thats just not the way I'd like to go if at all possible. edit: I just re-read your post. Are you suggesting the code do these steps:? 1) Get list of filenames in, for example, ./images/decks 2) Check if $dirArray[0] exists in ./images/decks, output with html if YES 3) If NO, create thumbnail, save. Output with html. 4) repeat. That makes sense to me, but I'm not sure how to use gd to actually create a new *.jpg int he event of a missing thumbnail. Foolio882 fucked around with this message at 21:54 on Mar 31, 2008 |
# ? Mar 31, 2008 21:50 |
|
Foolio882 posted:Oh dear god I think I'm hosed, as the function name suggests, this is supposed to be outputting a picture table and it's loaded with required html. Web browsers request and load images separately from HTML. I'd probably stick the resize image code in another php script; let's call it makeThumb.php for example. makeThumb.php takes in an image filename via GET and outputs the resized version. The displayPictureTable function would output a table containing HTML that refers to images generated by makeThumb.php, for example: php:<? foreach($imgarray as $img) { echo "<img src=\"makeThumb.php?img={$img}\"><br>"; }?> An elegant solution might include <img> tags that refer to images directly as if they already existed in a thumbnail directory (e.g. <img src="/img/thumbs/pic1.jpg">). If the appropriate thumbnail already exists, it will be loaded per normal. If not, a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. admiraldennis fucked around with this message at 22:01 on Mar 31, 2008 |
# ? Mar 31, 2008 21:52 |
Foolio882 posted:But that's what I am trying to avoid, having seperate thumbnails. You can use width and height on the <img> tag (which is a horrible way to do it) otherwise you are going to have to create separate thumbnails. Why is that such a bad solution if it's done automatically?
|
|
# ? Mar 31, 2008 21:58 |
|
fletcher posted:You can use width and height on the <img> tag (which is a horrible way to do it) otherwise you are going to have to create separate thumbnails. Why is that such a bad solution if it's done automatically? If it can be done automatically, I'm all for it and that will work just fine and dandy. I just did a bit of quick googling and found some very relevant information, and hopefully this will all come together nicely. (Read: I'll be back later with more awful questions, but you all have been very helpful and I do appreciate it!)
|
# ? Mar 31, 2008 22:14 |
|
Foolio882 posted:If it can be done automatically, I'm all for it and that will work just fine and dandy. I just did a bit of quick googling and found some very relevant information, and hopefully this will all come together nicely. Yeah, this is all pretty basic knowledge stuff. Did you read/comprehend my post?
|
# ? Mar 31, 2008 22:15 |
|
admiraldennis posted:Yeah, this is all pretty basic knowledge stuff. What can I say, I'm new to this stuff And yes, it all made sense to me, mostly. Would using GET and that makeThumb.php script you suggested work just as well for the one time "Oops, we don't have a thumbnail!" moments? The one part of your post I didn't fully comprehend was "a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. " I understand the goal there, and think it would work very well, but can you clarify what I've bolded? Is that what you already talked about with the makeThumb.php script?
|
# ? Mar 31, 2008 22:24 |
|
Foolio882 posted:The one part of your post I didn't fully comprehend was "a simple 404 redirection could point to a thumbnail generation script that would fetch the original image ('/img/pic1.jpg'), return the resized one to the browser, and then store the resized one in the thumbs for later use. " I understand the goal there, and think it would work very well, but can you clarify what I've bolded? Is that what you already talked about with the makeThumb.php script? By "a simple 404 redirection" I meant a system to redirect 404 errors that occur during requests to documents the thumbs directory to a specific php script. If the server was apache, you'd place an .htaccess file in the '/img/thumbs/' directory containing something like: code:
admiraldennis fucked around with this message at 22:58 on Mar 31, 2008 |
# ? Mar 31, 2008 22:56 |
What's a clean/efficient way to do bbcode replacements for format tags like [b], [i], etc?
|
|
# ? Apr 1, 2008 00:02 |
|
fletcher posted:What's a clean/efficient way to do bbcode replacements for format tags This has been done a lot. It would probably be a good idea to check out the source for a php package that has already implemented this. On the surface it looks easy, you could just replace all the [ b]'s with <strong> and all the [/b]'s with </strong>. But if you want it to be right you need to make sure there is a matching closing tag for every open tag and vice versa. Otherwise you could break the rest of your layout. You also need to check if the tags are nested properly. I am sure there are other issues as well.
|
# ? Apr 1, 2008 00:28 |
Begby posted:This has been done a lot. It would probably be a good idea to check out the source for a php package that has already implemented this. It does get quite confusing quickly trying to keep track of matching tags, nested tags, etc. What if I did the simple replace [ b] and [/b] with the corresponding html not paying any attention to if it's properly formatted at the end, and then use DOMDocument to correct any html problems? For example, this code: php:<? $doc = new DOMDocument(); $doc->loadHTML("<strong>test<i>italic"); echo $doc->saveHTML(); ?> code:
|
|
# ? Apr 1, 2008 02:01 |
|
fletcher posted:Which has corrected the malformed html. Is this a bad solution? It might be ok. Just test the ever living poo poo out of it with as much bad data as you can to make sure you get the desired results as you don't really know what is going on deep in the innards of DOMDocument. That is a pretty good idea btw, good thinking.
|
# ? Apr 1, 2008 02:13 |
|
fletcher posted:Which has corrected the malformed html. Is this a bad solution? You could probably also use HTMLTidy to clean it up.
|
# ? Apr 1, 2008 02:29 |
|
What kind of timestamps are these? 12314 12345 12356 12367 12378 12456 12859
|
# ? Apr 1, 2008 02:43 |
|
drcru posted:What kind of timestamps are these? Do you have any hints such as where you found these?
|
# ? Apr 1, 2008 02:51 |
|
It's in a MySQL table that I don't have access to yet. All I have is a printout of what the table looks like.
|
# ? Apr 1, 2008 02:58 |
|
fletcher posted:When I am validating fields submitted from a form I end up with a big if/else like: Heres another approach that I sometimes use php:<? $errors = array(); $success = true; if (!condition1) { $errors[] = "Condition 1 failed"; $success = false; } if (!condition2) { $errors[] = "Condition 2 failed"; $success = false; } if (!condition3) { $errors[] = "Condition 3 failed"; $success = false; } if (!condition4) { $errors[] = "Condition 4 failed"; $success = false; } if ($success) { // Do stuff } else { foreach ($errors as $error) { #Redraw the form and drop the errors into the template } } ?> Or just find one on the net. Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata.
|
# ? Apr 1, 2008 03:00 |
|
I suck at PHP, I admit. All I really know how to do is modify code already given to me, and somewhat follow what is going on. Anyway, let me cut to the chase. How do I do this: code:
|
# ? Apr 1, 2008 03:13 |
|
drcru posted:What kind of timestamps are these? The roll-your-own kind. Good luck figuring out that system! duck monster posted:Another tip, not really php, is hunt down an old javascript library called 'fvalidate' for the javascript side of it. But remember NEVER rely on javascript validation. fvalidate is neat however, since it just involves setting alt tags on input fields. Setting the alt tags is kind of neat, since it validates, and normally alt tags have no real role on input fields, so they are handy for hijacking for metadata. Alt tags on inputs are for screen readers. jQuery has a nice form validation plugin that uses class names or you can use JSON to build you validation requirements. Treytor posted:Without using curl, but fopen instead? Edit: duz fucked around with this message at 03:50 on Apr 1, 2008 |
# ? Apr 1, 2008 03:37 |
|
Treytor posted:I suck at PHP, I admit. All I really know how to do is modify code already given to me, and somewhat follow what is going on. Anyway, let me cut to the chase. http://us2.php.net/stream_context_create http://us.php.net/manual/en/wrappers.http.php (See example 1)
|
# ? Apr 1, 2008 03:42 |
|
Thanks for the input. I was also told that something like this would work as well: http://netevil.org/blog/2006/nov/http-post-from-php-without-curl But I am having a hard time wrapping my head around what to do, exactly. Like I said, I'm only into PHP about a week here, and I'm still trying to remember where to put the semicolons edit: This is what I've got: (ignore the stupid echo's I have in there) code:
code:
What am I missing here? The original code works perfectly on a server that supports curl, but that isn't an option... EDIT 2: It seems my server is being a bitch... Treytor fucked around with this message at 04:58 on Apr 1, 2008 |
# ? Apr 1, 2008 03:55 |
|
Question about PDFs: Is there a way to get an image of a particular page in a PDF? I'm interested in adding PDF thumbnails to a website, but can't find any capacity in PHP for reading PDFs rather than just writing them.
|
# ? Apr 2, 2008 01:20 |
|
chips posted:Question about PDFs: Google found this: http://www.webmasterworld.com/forum88/898.htm which has someone trying to do the same, and info on how to do it. Requires imagemagick, looks like.
|
# ? Apr 2, 2008 02:30 |
|
|
# ? May 15, 2024 03:49 |
|
chips posted:Question about PDFs: Shell out and use ghostscript: code:
|
# ? Apr 2, 2008 02:46 |