-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
At face value I don't see anything wrong with this code. What have you done to know it's not the same?
-
It's basically a cheap (and often dangerous) way to convert one variable type to another. There's not enough info here to be sure, but if I had to guess, I'd say $child->tid is an object (like maybe a json object from a request or response or xml object) being converted to an array, most likely for no other reason than it being easier for whoever coded it to handle the data (e.g. loop through it). $child->name[0] is probably already expected to be a string but is being typecasted to string type to be safe (e.g. maybe it's possible $child->name[0] could also be a number). For the latter, that's usually not needed, since php is loosely typed and will do type conversion automatically. But there are some php functions that php fails on. For example, ctype_digit checks to see if a string only contains numbers, but if you try to do ctype_digit(12345) you will get an error (crazy, huh?), so you have to typecast to keep it from breaking.
-
try swapping the quotes. php -r "echo 'hello world';"
-
[] is a character class and will match any one thing in it. So doing something like this or [\d] is superfluous; you'd just put S or \d (or whatever) without the [] surrounding it. In fact, \d itself is a character class. It's shorthand for [0-9]. So to match for S or an E, you would have [sE]. But since you want to match an S optionally followed by an E, then you'd do SE?. Also, you're matching for a forward-slash but you're also using that as the pattern delimiter. So you have to escape the forward-slash in your pattern or else use a different pattern delimiter. I personally like using ~ since it rarely ever comes up, and / is pretty common because php is used with web stuff so matching paths and (x)html is common and / is a common symbol in them. # is also a popular alternative. So overall, you should just have ~^SE?\d{5}/\d{4}$~ As to your first question: I'm going to assume that you tried just removing if( empty($errors)) and that "didn't work". Well that line isn't directly part of your email regex condition, so I can't tell you why it "didn't work" or how to remove it in a way that "works". You're going to have to explain what you mean by "didn't work". What is (not) happening that you (don't) want to happen?
-
// this is the path to where your folders are located $basePath = 'path/to/where/folders/go/'; // the folder name you are saving/retrieving in your database. $reference = 'somefolder'; //this is the full path/to/folder $folder = $basePath.$reference; // if the folder doesn't already exist... if (!file_exists($folder)) { // create the folder mkdir($folder); }
-
$content = '<div><b>username<hr> </b></div>'; $content = str_replace('<div><b>username<hr> </b></div>','',$content);
-
Post the code that actually executes it. Multiple queries in a single request may or may not be possible, depending on what code you're using.
-
Don't be fooled. His productivity merely went from 10% capacity to 20%.
- 10 replies
-
- ide
- text editor
-
(and 2 more)
Tagged with:
-
The most immediate thing I see wrong is a comma after deleted='1',
-
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
if (($halePostData === 1) || (self::PostData())) { if the first part: ($halePostData === 1) is true, it will not evaluate the rest of the condition, since only 1 of them have to be met. This is called short circuiting. logical operators -
I have come to like nano more than vim when SSHing to a server (I use windows locally so I give the finger to BOTH as far as LOCAL editing lol)
- 10 replies
-
- ide
- text editor
-
(and 2 more)
Tagged with:
-
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
well i'm willing to believe some of the indention might have been lost in posting, but I can tell from your code that you aren't properly indenting anyways. copy/paste issues wouldn't put several closing brackets and lines of code on one line while leaving the same type on others like that. I'll give you a hint: Looks like the issue is missing closing brackets in function MemberRouter -
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
go through your code and properly indent it manually then. You'll find the missing bracket soon enough. Sorry, I'm not going to do that for you. That's one of the points of getting into the good habit of indenting your code! -
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
There are plenty of IDEs and code editors out there that highlight opening/closing bracket pairs, as well as "fixes" or "beautifies" code (indenting properly) which makes it a lot easier to visually find out which one you are missing. -
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
And this further affirms that you've lost track of your opening/closing brackets. More specifically, you're missing a closing bracket somewhere -
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
That error is a result trying to execute code within a class definition that's outside of a method. IOW you are basically doing this: class NoobMember { function __construct($data) { } function PostData() { echo "something"; } $noob = new NoobMember; // bad $noob->PostData(); // bad } IOW basically you have lost track of your opening/closing brackets and have put that code inside your class definition where it doesn't belong. -
some example queries Get a listing of all the data in one place: SELECT f.filename, f.thumbnail, fk.file_id, fk.keyword_id, k.keyword FROM Files AS f LEFT JOIN Files_Keywords AS fk ON f.id = fk.file_id LEFT JOIN Keywords AS k ON fk.keyword_id = k.id results: filename thumbnail file_id keyword_id keyword somefile.pdf someimage.pdf 1 1 foo somefile.pdf someimage.pdf 1 2 bar somefile.pdf someimage.pdf 1 3 blah anotherfile.pdf anotherimage.jpg 2 1 foo anotherfile.pdf anotherimage.jpg 2 2 bar anotherfile.pdf anotherimage.jpg 2 4 something anotherfile.pdf anotherimage.jpg 2 5 dog Get all filenames/thumbails for keyword "foo": SELECT k.keyword, f.filename, f.thumbnail FROM Files AS f LEFT JOIN Files_Keywords AS fk ON f.id = fk.file_id LEFT JOIN Keywords AS k ON fk.keyword_id = k.id WHERE k.keyword = 'foo' results: keyword filename thumbnail foo somefile.pdf someimage.pdf foo anotherfile.pdf anotherimage.jpg Get all the keywords for somefile.pdf: SELECT f.filename, k.keyword FROM Files AS f LEFT JOIN Files_Keywords AS fk ON f.id = fk.file_id LEFT JOIN Keywords AS k ON fk.keyword_id = k.id WHERE f.filename = 'somefile.pdf' results: filename keyword somefile.pdf foo somefile.pdf bar somefile.pdf blah
-
First, an explanation of what the tables/columns are for: Table Files - this is pretty much setup same way as you had it before, except without the keywords column (because you now have a separate table for them) id - this should be a unique value for each row (file), the primary key. filename - this is the name of the file like somefile.pdf thumbnail - this is the thumbnail for the file somefile.jpg Table Keywords - this table will just have the keywords and a unique id for them. All keywords for all files should be here. There should be no duplicate keywords id - this should be a unique value for each row (keyword), the primary key keyword - the keyword, like "dog" or "cat" Table Files_Keywords - this is the table that joins the two other tables file_id - values in this column should be the same as your Files.id column keyword_id - values in this column should be the same as your Keywords.id column So the main magic here is in Files_Keywords. This table is basically a lookup table to establish a relationship between Files and Keywords. So going back to my example data: Table Files id filename thumbnail 1 somefile.pdf someimage.jpg 2 anotherfile.pdf anotherimage.jpg Table Keywords id keyword 1 foo 2 bar 3 blah 4 something 5 dog Table Files_Keywords file_id keyword_id 1 1 1 2 1 3 2 1 2 2 2 4 2 5 In Files_Keywords, the first 3 rows are for the file that has an id of 1. In table Files you see that somefile.pdf has that id. So you see that each row with file_id of 1 has a different keyword_id value. That's the id from Keyword. So in this example, I show that somefile.pdf is associated with keywords "foo" "bar" and "blah". Then the next 4 rows in Files_Keywords are for anotherfile.pdf, and the keyword_id values show that it also has keywords "foo" and "bar" associated with it, but also has "something" and "dog" as well.
-
Well no, actually this forum does (attempt to) have a conscience. We aren't here to help people make the internet a worse place. Just like we aren't here to do people's work for them. That's like a scientist claiming they did nothing wrong for creating the next wmd or some killer virus, claiming it's not his fault someone else abused it. But you aren't judging them solely on a piece of code. You know damn well what they want to do with it, and you're teaching them anyway. It's like someone asking you how to shoot a gun or to buy a gun from you and they tell you they want to learn/buy because they want to murder someone. You are no longer just teaching them to use a gun. You are no longer just selling them a gun. Because you know what their intentions for it are, you are now responsible for more than just teaching/selling. You are now an accomplice or aiding and abetting them. And even if you disagree that there are moral obligations and responsibilities for that, then at a minimum you have to acknowledge that there are legal ramifications. Because there are. And saying "I didn't pull the trigger" isn't a good enough defense in the legal world. It may not land you the same punishment as the trigger puller but it will definitely not walk away free and clear.
-
verbose execution without slash happy selfmutilation?
.josh replied to Augury's topic in PHP Coding Help
based on your posts i feel as though you've lost touch with a lot more than coding.. i feel like i'm watching a coked up ferret with adhd. Do you mean like debug_backtrace? -
You shouldn't have a single column with multiple keywords to search through. It's possible to work with what you have as-is, but it's inefficient, especially if/when you need to get into selecting files with common keywords or visa versa. What you really should do is have 3 tables so as to have a many-to-many relationship between your files and the keywords. Example you'd have Table Files id filename thumbnail 1 somefile.pdf someimage.jpg 2 anotherfile.pdf anotherimage.jpg Table Keywords id keyword 1 foo 2 bar 3 blah 4 something 5 dog Table Files_Keywords file_id keyword_id 1 1 1 2 1 3 2 1 2 2 2 4 2 5
-
Seems to me that mysqli_free_result frees all of the result memory, so there's no specifying individually bound results. IOW binding results to vars just creates individual references to the core result source. Sidenote: perhaps it might be helpful if you provided more background to what you're trying to do. As it stands in your code, there's no real gain from doing this.. or from closing the statement/connection at the end of your script like that. php automatically closes and frees everything at the end of script execution. The only time it's really beneficial to do this sort of thing is if you're working with a database and getting results.. but then the script still has a lot of stuff to do afterwards and you don't want the db stuff sitting in memory causing the rest of the script to run slower.
-
Dynamically create class properties from all of constructor's arguments
.josh replied to Hubble's topic in PHP Coding Help
Little bit unclear, perhaps a pseudo-code example might help clarify what you really want, but it sounds like maybe you want func_get_args -
that doesn't sound like a problem with javascript, but a problem with server-side settings or coding. Ex: .htaccess mod rewrite doing a redirect and not passing the query string, or code in index.php itself doing a redirect and not passing the query string