Jump to content

Mike521

Members
  • Posts

    29
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Mike521's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm generating a PNG image (transparent background) of some text on the fly. The text will be whatever the user typed, using English 111 Vivace BT (a script) as the font. The image will always be 100px tall by 200px wide, regardless of how large the text is. I want the text to be horizontally centered and positioned as close to the top of the image as possible. This all works generally fine except that imagettfbbox() appears to be returning incorrect points for the bounding box, it thinks the text is taller than it really is, and therefore some blank space is appearing at the top of the image, before the text. Please see the attached example png, I drew some red guidelines to demonstrate the problem. The left side shows a guideline that is 38px tall, which is what imagettfbbox() thinks is the height of the text. The right side shows a line measured against the text itself, and it's only 26px tall. is there a more accurate way to get the box?
  2. thanks salathe, that looks perfect! kenrbnsn, that's what I was doing? As it turned out I decided to use a database and have a separate column called "processed" that I set when the orders have been processed. Only drawback is I'll have to clean the DB once a week or so, but I prefer this method over the flat files
  3. I have a text file that is written to by two scripts: 1. writes order data whenever a new order comes in 2. must read the order data and then erase the file, twice a day This way every time script 2 runs, it has only the new orders, none that have already been read. Each of the scripts does an flock to make sure the other one doesn't access it while it's making changes. Problem is, after script 2 reads all the orders, I want to erase the text file. If I close the file and then reopen it in "w" mode, there'll be a split second where the file is available to be written to by script 1. So is there a way to open the file for reading / writing, and completely blank it out after reading is complete? I also thought about doing a file_get_contents to read it with script 2, then opening it in "w" mode, but I think it could still be written to again between the file_get_contents and the fopen. Here's some code, thanks in advance for any suggestions Script 1: runs frequently throughout the day at random times <?php echo "working"; if ( $file = fopen( "orders.txt", "w" ) ) { if ( flock( $file, LOCK_EX ) ) { //write some stuff } else { echo "<br>couldn't acquire lock..."; } } else { echo "<br>couldn't open file..."; } fclose( $file ); echo "done"; ?> Script 2: runs twice a day on schedule <?php if ( $orders = fopen( "orders.txt", "r+" ) ) { // open for reading and writing if ( flock( $orders, LOCK_EX ) ) { // file is locked, we can read it then erase it // first read the whole file while ( !feof( $orders ) ) { $allOrders .= fgets( $orders, 4096 ); } // here is where we want to erase the file and close it } else { echo "<br>could not lock orders.txt"; } } else { echo "<br>cannot open orders.txt"; } fclose( $orders ); ?>
  4. Is there a way to install PHP on my vista machine simply so I can use it to do syntax checks before uploading my files to the server? Sometimes I do not have the ability or the time to do a good test (upload a test file, check it, then modify the live file). In these instances it would be very useful if I can do a simple syntax check before uploading, to catch a missing comma or semi colon. Is there an easy way to do this? I'm using Dreamweaver CS 3 on Vista Ultimate thanks
  5. I think I finally figured it out. instead of converting miscellaneous characters to entities, I figured what the hell, if I can get them to utf8 then why should I encode them? so I just utf8 encode the incoming data, replace only the worst characters ( & < > ) with their entities, urlencode, and send. seems to work fine so far.
  6. It seems like the problem is the entity references though. %26Ntilde%3B becomes Ñ when it's received. Then simplexml gives the error "Entity: line 23: parser error : Entity 'Ntilde' not defined" Is there a way to tell simplexml to expect those types of entities, perhaps?
  7. I am in character encoding hell, I hope someone can get me out! I have a web form encoded in ISO-8859-1. It posts to another ISO-8859-1 page. That page takes the post data and sends it to a script that runs in the background. The script's job is to convert the post data into xml, and then post it to yet another script that will process it. The problem I run into is when there are spanish characters on the input. It seems no matter how I try to encode them, the final receiving script always either ignores all the incoming data, or ignores the fields with spanish characters. It seems to me that the problem is happening in the last post. For example here is what my xml data might look like right before I send it: <?xml version="1.0" encoding="utf-8"?> <data> <spanishStuff>here+are+some+span+chars+%26Ntilde%3B+%26ntilde%3B%26euml%3B%26oacute%3B</spanishStuff> </data> The very first thing I do on the final script is email the post data to myself. Well here's what it looks like: <?xml version="1.0" encoding="utf-8"?> <data> <spanishStuff>here are some span chars Ñ ñëó</spanishStuff> </data> See how the %26's have been replaced with &? Well then when I do a simplexml_load_string, it gives me warnings such as "parser error : Entity 'Ntilde' not defined". After that, all the input is either ignored, or the fields with spanish chars are ignored, depending on which variation of encoding I've tried this time around. I don't know what to do at this point, I've spent a lot of time trying TONS of ways to encode the data, either before I send it or after I receive it, and nothing seems to help. For what it's worth, one of the first things I do is utf8_encode the incoming post data since the web form is in ISO Here is a step-by-step of the process if you want further clarification: 1. user enters data on ISO-8859-1 page 2. data is posted to a receiving ISO-8859-1 page 3. receiving page spawns a background process (using http_build_query on the post data, and fsockopen / fwrite to send it) -- background process ignores user disconnect 4. background process takes the post data and forms it into XML. -- as it does so, it encodes the data in UTF8, htmlentities, and urlencode 5. background process uses cURL to post the xml string to the final, receiving script 6. receiving script grabs the data and does whatever it needs to do the background process technically can be skipped, but we don't want the user waiting around while all this other stuff happens, so I simply tell them thank you and let the system do the rest. hope someone can help, thanks
  8. Anyone know of a way to convert windows 1252 into UTF-8? For example our database has lots of product descriptions that unfortunately have fancy quotes and double quotes (probably from MS Word etc). I want to change the charset on our web pages to UTF-8, but the quotes get messed up. Using utf8_encode doesn't work because it wants an ISO string as input, not 1252. Thanks in advance
  9. I figured it out, the following lines were bugged: $theInventoryName = "Item_x0020_Stock_x0020_$style_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_$style_Qty_x0020_on_x0020_Sales_x0020_Order"; The variable was $style, but the way I tried to insert it into this string, PHP thought I was looking for a variable called $style_Inventory, similarly for the next line. I changed them to: $theInventoryName = "Item_x0020_Stock_x0020_" . $style . "_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_" . $style . "_Qty_x0020_on_x0020_Sales_x0020_Order"; and it worked perfectly
  10. this is the original xml: <?xml version="1.0" encoding="utf-8"?> <Dynamics_x0020_NAV_x0020_Data> <Item_x0020_Stock_x0020_3406S> <Item_x0020_Stock_x0020_3406S_Inventory>22964</Item_x0020_Stock_x0020_3406S_Inventory> <Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order>1197</Item_x0020_Stock_x0020_3406S_Qty._x0020_on_x0020_Sales_x0020_Order> </Item_x0020_Stock_x0020_3406S> </Dynamics_x0020_NAV_x0020_Data> I'm trying to pull the values of 3406S_Inventory and 3406S_Qty I forgot to put in the first post: $style = 3406S;
  11. I've probably been looking at this too long and need to just take a break. I have the following data in XML form, brought into an object via simplexml_load_string: object(SimpleXMLElement)#1 (1) { ["Dynamics_x0020_NAV_x0020_Data"]=> object(SimpleXMLElement)#2 (5) { ["Item_x0020_Stock_x0020_3406S"]=> object(SimpleXMLElement)#3 (2) { ["Item_x0020_Stock_x0020_3406S_Inventory"]=> string(5) "22964" ["Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order"]=> string(4) "1197" } } } When I try to get the data (aka the inventory) it comes up blank. But if I want the value of "Item_x0020_Stock_x0020_3406S" it returns data. For example the following code: $theInventoryObject = "Item_x0020_Stock_x0020_$style"; $theSalesOrderObject = "Item_x0020_Stock_x0020_$style"; $theInventoryName = "Item_x0020_Stock_x0020_$style_Inventory"; $theSalesOrderName = "Item_x0020_Stock_x0020_$style_Qty_x0020_on_x0020_Sales_x0020_Order"; $theItemInventory = $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject->$theInventoryName; $theItemSalesOrder = $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theSalesOrderObject->$theSalesOrderName; echo "<br>Item Inventory: $theItemInventory<br>Item Sales Order: $theItemSalesOrder<br>"; echo "<br>Inventory Object:<br>"; var_dump( $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject ); echo "<br>Sales Object:<br>"; var_dump( $theStockReturn->Dynamics_x0020_NAV_x0020_Data->$theInventoryObject->$theInventoryName ); outputs this: Inventory Object: object(SimpleXMLElement)#14 (2) { ["Item_x0020_Stock_x0020_3406S_Inventory"]=> string(5) "22964" ["Item_x0020_Stock_x0020_3406S_Qty_x0020_on_x0020_Sales_x0020_Order"]=> string(4) "1197" } Sales Object: object(SimpleXMLElement)#12 (0) { } Item Inventory: Item Sales Order: Can anyone see what I'm missing?
  12. well if nothing else at least I can switch to mt_rand. I'll have to look at javascripts and such to see if there's something redirecting people from page B to page A.. thanks everyone for taking a look at the code for me
  13. yep that's the goal, I want it to be as close to 50/50 as possible but for one reason or another, 67% of our visitors are doing group A's search, rather than 50%. I guess there's a problem outside this PHP code
  14. hmm I'm not sure which is faster myself. I'll switch to it, but I don't think the method is the cause of the problem, does everyone agree? If not, try this yourself: $groupA = 0; $groupB = 0; for ( $i = 0; $i < 1000000; $i++ ){ $random = rand()&1; if ( $random == 1 ) { //echo "<br> it's a 1 (group B)"; $groupB++; } else { if ( $random == 0 ) { //echo "<br> it's a 0 (group A)"; $groupA++; } } } echo "<br>group A: $groupA<br>group B: $groupB";
  15. I ran a modified version of the script that simply looped 1 million times and tallied up A vs B (using the method I posted earlier). it was almost exactly 50/50, so I'm confident that it's accurate. Regardless, so far we have 2,296 searches. 1,539 were in group A (67%), 757 were in group B (33%). everything seems correct to me but I can't figure out why there's such a big discrepancy
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.