|
An easy question (probably): I have a record in a database that contains the < and > characters (Entrails<VP> is the element in question). When I generate an html page based on that data, the interpreter strips them off as an html tag. So: Entrails Entrails<VP> becomes Entrails Entrails causing some confusion. Without manipulating the data in the database, how can I force PHP to produce a page that displays the <> characters?
|
# ¿ Aug 14, 2008 19:16 |
|
|
# ¿ May 7, 2024 18:19 |
|
Thanks.
|
# ¿ Aug 14, 2008 19:22 |
|
I am trying to create a PHP applet that will monitor IIS log files (using the tail command) for a specific event and perform an action when that event is found. I know how to parse a log file when it is written to disk, but how do I do this in such a way that the real time log stream is monitored?
|
# ¿ Sep 8, 2008 19:03 |
|
Munkeymon posted:I guess you could do this: That's what I want. We are getting a bunch of SQL injection attacks on our web site, so I want to write a script that pulls the source IP address from the IIS log file as it happens and keep a tally of them per hour. This seemed the easiest way of doing it.
|
# ¿ Sep 9, 2008 00:04 |
|
I need help breaking up lines of data in a flat file into variable to be imported into a database, and explode() doesn't seem to cut it. The data that I have is in this format code:
1-18: Name 20-23: HexNbr 25-33: UWP (eight sub-variables with a length of 1 each. the hyphen will be omitted) 36: Bases 38-52: Codes & Comments (up to seven sub-variables, space delimted) 54: Zone 57-59: PBG (three sub-variables with a length of one each) 61-62: Allegiance 64-80: Stellar Data (Up to six sub-variables, space delimted) Explode() will split it up using a delimiter like " ", but what I'd like to do is specify some method where I can grab some characters out of the string of some specific length and stuff it into a variable. The length of the grabbed data varies and will potentially contain spaces in it. How can I accomplish this?
|
# ¿ Jun 15, 2009 19:42 |
|
How do I insert items randomly into an array of fixed size and avoid collisions? I have a list of items that I need to insert randomly into an array. The number of items will always be smaller than the size of the array and in the event of a collision I need to pick another random spot in the array. How can I do this?
|
# ¿ Jul 21, 2009 21:59 |
|
supster posted:I can almost gaurantee there's a better way to do what you're trying to accomplish. What are you trying to accomplish? shuffle may be what you're looking for. To pull out the :nerd: hat here, I am writing a script that generates a star system around existing data based on the rules set forth in the MegaTraveller RPG. I have a database of approximately 50,000 star systems and each system has 1-4 suns, 0-7 gas giants, 0-3 asteroid belts and assorted worlds. The game's star system generation chapter has a pretty detailed method for generating orbital bodies in a star system and I am automating it using php/mysql. My current thought is to have an array that represents the orbits of the system and all of the sub orbits (for moons around worlds, binary & trinary systems, etc). The rules have a complicated method to place suns in a system randomly but with many modifiers, then to place gas giants, then belts, then worlds each with its own set of rules and modifiers. Since an orbit can only contain one object, rerolls are necessary. Here's the core of what I have so far, but it's broken. It doesn't check if the array is occupied properly, so if the array item is occupied, it gets overwritten buy the incoming record: code:
|
# ¿ Jul 21, 2009 23:20 |
|
supster posted:I also just noticed this in your code: Yeah. The point was to keep rolling and keep trying to find a slot in the array that wasn't filled yet. Once it found an empty slot, it would break out of the loop. This code snippit was going to be a function that would be called many times for placing stars, gas giants, belts and worlds, and I figured that many rerolls might be necessary in more crowded systems, which is okay with me.
|
# ¿ Jul 22, 2009 06:14 |
|
Two things: I have this code: php:<? $Size = 0; if ($Size === "S" || $Size === 0) $Test = "S"; if ($Size === "LGG") $Test = "LGG"; if ($Size === "SGG") $Test = "SGG"; if ($Size > 0 && $Size <=9) $Test = $Size; if ($Size === "A" ) $Test = "A"; echo $Test; ?> Agrikk fucked around with this message at 07:09 on Sep 18, 2009 |
# ¿ Sep 18, 2009 07:03 |
|
Is there an way to search for the existence of a value in multiple variables at once? For example, if I have: $variableone = "do"; $variabletwo = "ray"; $variablethree = "mi"; $variablefour = "fa"; $variablefive = "so"; Is there a function that I can use to search for the existence of "fa" in any of the five variables? I could easily write a bunch of seperate if/else statements to so this, but I'd like to come up with something a little bit more elegant.
|
# ¿ Sep 21, 2009 22:34 |
|
Good idea. Thanks.
|
# ¿ Sep 21, 2009 23:05 |
|
Why is this code returning "Hello missing"? It should find Hello in the array and thus not return anything.php:<? $aa = 0; do { $bb = 0; do { $cc = 0; do { $SystemArray[$aa][$bb][$cc]='xx'; $cc++; } while ($cc < 3); $bb++; } while ($bb < 3); $aa++; } while ($aa < 3); $SystemArray[0][1][2]='Hello'; $str = "Hello"; if (array_search($str, $SystemArray)=== false) echo "\n$str missing\n"; ?>
|
# ¿ Oct 1, 2009 00:06 |
|
fletcher posted:First of all, use for loops. Second of all, $SystemArray only contains 0, 1, 2. It does not contain "Hello". The array $SystemArray[0][1] does contain "Hello" though. if I do a print_r($SystemArray) I get: code:
|
# ¿ Oct 1, 2009 18:52 |
|
Golbez posted:What does a var_dump($SystemArray) show? code:
|
# ¿ Oct 1, 2009 19:02 |
|
So clearly I am doing something wrong and don't understand arrays Why doesn't this work? php:<?php //load up multidimensional array with "xx" for ($aa=0; $aa < 2;$aa++) { for ($bb=0; $bb < 2;$bb++) { for ($cc=0; $cc < 2;$cc++) { $SystemArray[$aa][$bb][$cc]="xx"; } } } //change one element to "Hello" $SystemArray[1][1][1]="Hello"; //print array to be sure it's there print_r($SystemArray); //find "hello" $IsThere="no"; for ($aa=0; $aa < 2;$aa++) { for ($bb=0; $bb < 2;$bb++) { for ($cc=0; $cc < 2;$cc++) { if ($SystemArray[$aa][$bb][$cc]==="Hello") $IsThere="yes"; } } } if ($IsThere="no") { echo "not found\n"; } else { echo "found\n"; } ?>
|
# ¿ Oct 1, 2009 19:22 |
|
Standish posted:Also using strings "yes" and "no" instead of booleans is just shameful. Getting off topic for a second, what does it matter if I use strings or booleans? Is it a performance issue or something? Agrikk fucked around with this message at 19:43 on Oct 1, 2009 |
# ¿ Oct 1, 2009 19:30 |
|
Standish posted:It's slower to use strings, yes, but the main thing is style and avoiding horrible bugs like [php]$a = "no"; Thanks for your help Standish. I just realized that that was my error. I always get tripped up between =, == and ===. Meh.
|
# ¿ Oct 1, 2009 19:45 |
|
Is there a way other than a set of IF statements that can perform a set of commands depending on what a variable is? Like if $color is "red" do <command set 1> but if $color is "blue" then do <command set 2> but if $color is "green" do <command set 3>. I found it. it's the Switch structure. Agrikk fucked around with this message at 04:48 on Oct 18, 2009 |
# ¿ Oct 18, 2009 04:46 |
|
I have a variable whose values can be anywhere from millions down to ten-thousandths stored in a MySQL database as type Decimal with a length of twelve and four decimal places. The problem is that when calling them though PHP I end up with results like: 0.3900 0.0001 4500000.0000 I would like the results to appear as: 0.39 0.0001 4,500,000 How can I truncate any zeros after the final digit to the right of the decimal point? Agrikk fucked around with this message at 19:41 on Jan 12, 2010 |
# ¿ Jan 12, 2010 19:19 |
|
gwar3k1 posted:Cast the number to a string, check for a decimal point, explode it at the decimal, check each number for avalue higher than 0, if the last number is true then keep it else ignore it. That's a good one. Thank you. Edit: Here's what I did: php:<? function TruncateZeros($number) { list($front, $back) = explode(".", $number); if ($back <>0){ $array = array($front,$back); $dot_separated = implode(".", $array); echo "$dot_separated"; } else { echo "$front"; } } ?> Agrikk fucked around with this message at 02:07 on Jan 13, 2010 |
# ¿ Jan 12, 2010 22:58 |
|
How can I pull windows extended file properties information from a file within PHP? I am writing a script that organizes photos (.JPGs) based on the date of the picture. However my original attempt uses DIR /OD to call the list of files, however what I need is the metadata "Date Taken" not "Date Created", which makes DIR /OD not what I need. Agrikk fucked around with this message at 07:10 on Nov 21, 2010 |
# ¿ Nov 21, 2010 07:00 |
|
FeloniousDrunk posted:You probably want the EXIF data, specifically the FileDateTime I think. Perfect. THat is exactly what I needed. EXIF.DateTimeOriginal did the trick. Agrikk fucked around with this message at 05:26 on Nov 22, 2010 |
# ¿ Nov 22, 2010 05:05 |
|
I am connecting to a SQL Server 2014 instance using PHP 5.4.24 and I am trying to figure out why this isn't working:code:
|
# ¿ Jun 29, 2015 04:17 |
|
Biowarfare posted:..also why are you.. why.. Why not? code:
Agrikk fucked around with this message at 04:41 on Jun 29, 2015 |
# ¿ Jun 29, 2015 04:37 |
|
This is an AWS / DynamoDB question using PHP, so I'll try here first: I am working on a PHP script that will load a million rows from a tab delimited text file into DynamoDB every hour. I have worked my way through putItem and batchWriteItem and am now trying to figure out how to make WriteRequestBatch work. The relevant bit of code I have is: code:
When I run this code I receive the following error: code:
|
# ¿ Jul 20, 2016 22:23 |
|
Agrikk posted:This is an AWS / DynamoDB question using PHP, so I'll try here first: For posterity: The answer was that while SDK v2's Aws\DynamoDb\Model\BatchRequest\WriteRequestBatch had a factory method, v3's Aws\DynamoDb\WriteRequestBatch does not. I replaced the r line calling that method with this: code:
|
# ¿ Jul 26, 2016 01:18 |
|
Can someone point me to a good resource for learning how to batch insert items into a MySQL database using PHP? I have a tab-delimited file of 1.1 million rows that I want to insert into a MySQL database (it's actually AWS Aurora) every hour. Most of the examples I find online are of people using arrays to receive the data from the flat file and then using loops to push the data into the database. But iterating over a million-member array one at a time seems dumb and inefficient.
|
# ¿ Jun 6, 2017 17:53 |
|
I am building an IIS-based PHP web site on AWS located in three regions across the globe. On the back end I have a trio of database servers replicating across those regions and I want each pool of web servers to access their local database node above all the others. I have a single DFS share that spans the three regions so I can make a single code push to the DFS share and all web servers in each of the three pools gets an update. So I have created a test Config.php file that looks like this: code:
Hello OS: Windows_NT AZ: us-west-2a Server: 10.1.1.50 as expected. But when I run the script by accessing it in IIS I get Hello OS: Windows_NT AZ: Server: Somehow PHP is not able to fetch EC2-InstanceAZ from the list of system variables inside IIS even though it can pull a different system variable. Does anyone have an idea?
|
# ¿ Dec 8, 2019 22:31 |
|
nielsm posted:At what point is your environment variable getting set? These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions). What is bugging me is that I can pull other system variables (like OS, DriverData) but EC2-InstanceAZ, EC2-InstanceId, etc chokes. Agrikk fucked around with this message at 20:33 on Dec 9, 2019 |
# ¿ Dec 9, 2019 19:43 |
|
Pile Of Garbage posted:A few things: The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted. itskage posted:But why?? quote:Also this, especially the multi-AZ DFS Because I have some spare time, and the free resources with which to goof off . And most importantly, because I can.
|
# ¿ Dec 11, 2019 08:14 |
|
It turned out to be an IIS thing, not a PHP thing, but the answer was to turn on "Load User Profile" for the application pool.
|
# ¿ Dec 11, 2019 17:35 |
|
a hot gujju bhabhi posted:Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around? I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive.
|
# ¿ Dec 11, 2019 21:50 |
|
Eh, I hear what you are saying and ordinarily I recommend going LAMP to learn PHP, but in this case I’m building a Rube Goldberg setup intentionally. As it turns out, the back-end is actually a set of databases in three regions including Aurora Postgres, RDS SQL Server, SQL Server Availability Groups and stand-alone but load balanced SQL on EC2. All serving up the same data sets. So PHP on IIS with the web sites running off of DFS is hardly the weirdest design decision I have going on here.
|
# ¿ Dec 13, 2019 17:20 |
|
Looking for memcached help now. Same app as above... So I have a SQL Server table that is [userID],[timestamp],[data1] and I have a PHP-based web application that returns [data1] for all [timestamp] for a specific [userID]. It returns in a tabular format: http://folding.rainwalk.net/UserHourlySummary.php?UserName=Agrikk&TeamNumber=33 I'm experimenting with AWS Elasticache to speed up database performance and I'm wondering how to make it all work. I understand the basic mechanism with PHP that you write a check to see if the key exists in cache then use that, and if it doesn't then fetch it from a database and also copy it into cache. My question is more around how memcached "knows" that data in the database has been updated. If the above table receives INSERTS at a rate of one batch every 60 minutes, and data older than 14 days is purged, what is the optimal way to fetch the data in PHP so that data lives in cache for 14 days and what is the optimal way to retrieve the data during page load so that it pulls the majority of the data from cache and the remainder from the database? Right now my PHP page runs a SELECT statement and then uses a code:
What is the best practice here? Agrikk fucked around with this message at 02:22 on Dec 24, 2019 |
# ¿ Dec 24, 2019 02:15 |
|
joebuddah posted:What sqlsrv fetch command do I need to use for json data? I don’t understand. Are you asking how to import a JSON document into SQL Server? Or how to pull data from SQL Server as JSON to consume?
|
# ¿ May 2, 2020 17:38 |
|
Can someone help me with a check to see if a row is complete? I have a file of tab separated values, and some rows are incomplete, which breaks my processing. How can I check to see if the row is incomplete so I can do something else with it? code:
|
# ¿ May 5, 2020 04:58 |
|
I am bashing my head in over this one. I am trying to install the php_yaml.dll extension on my windows server (Server 2019 Datacenter v1809) with PHP version 7.0.21 (Thread Safety: Enabled) and I am getting the following error when running php.exe from the command line: "Warning: PHP Startup: Unable to load dynamic library 'c:\php\ext\php_yaml.dll' - The specified module could not be found." I have other extensions in the exact same place (c:\php\ext) being accessed the same way (extension=<module>.dll) in c:\PHP\php.ini. I have tested the configuration settings in PHP.ini by renaming an active .dll file which immediately causes the same "Unable to load dynamic library" to show up, so I know the settings are pointing to the right places. For some reason PHP can't see php_yaml.dll. I have tried php_yaml-2.0.4-7.0-nts-vc14-x64 and php_yaml-2.0.4-7.0-ts-vc14-x64 and php_yaml-2.0.4-7.1-ts-vc14-x64 and they all behave the same way. I even tried php_yaml-2.2.1-7.4-ts-vc15-x64 and got a different error about "the procedure entry point" couldn't be located, which I'm sure has to do with the wrong version of VC14 vs VC15, but at least I know that PHP is looking in the right place for the file. So why cant PHP find php_yaml.dll?
|
# ¿ Jan 27, 2021 07:28 |
|
Nope. Full control on all the Dlls. I even tried moving all of my enabled DLLs to a new folder path and all of them work except for the yaml one.
|
# ¿ Jan 27, 2021 08:22 |
|
Well drat. There's an hour of my life I won't get back. Turns out that Biowarfare posted:see step 5 of https://stackoverflow.com/a/27379895 - this is no longer relevant with the newer versions of php_yaml but since you are on such an old version, this may be why; php_yaml wraps yaml.dll and yaml.dll needs to be available on the path was the solution. I saw zillions of people saying "add yaml.dll to C:\wamp64\bin\php\phpX\" but I figured that since I was running PHP command line only and not WAMP I didn't need that step. Turns out a better step would be "put yaml.dll somewhere that PATH can see it". Thanks thread! FWIW: I'll be upgrading to 8 eventually, but I have so many different workloads running on 7 and I'm afraid that 8 will break things that I hesitate to pull the trigger.
|
# ¿ Jan 27, 2021 16:38 |
|
|
# ¿ May 7, 2024 18:19 |
|
Follow up on my YAML stuff: How do I pull elements out of nested PHP (7.0.2) arrays and assign each item to a variable so I can shove the data into a database table? Given a yaml file like this: code:
I've managed to parse the file into an array using yaml_parse_file(<filename>) and have pulled the top level stuff and the second level "planet" information using lines like code:
|
# ¿ Jan 28, 2021 01:06 |