-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
That code will echo the var and when it all gets sent to the browser, the js will execute with the hardcoded var output. I hope you are not thinking the js will execute server-side...
-
also, the pattern you came up with: preg_match_all("/\[img file\:\"[^\"]*\.[^\"]{3,5}\" alt\:\"[^\"]*\" \/]/", $test, $matches); It technically probably will work, but first off, you're using a negative char class matching anything but a " up until a literal dot. So the negative character class should be a \. instead of \" (don't need to escape that quote either...). Also for the 2nd negative char class, you are specifying a range, so it would be okay to just use .* instead of the negative char class. Overall, I'm not really sure why you are wanting to even specifically look for a . and 3-5 chars... if you're shooting for actual file validation, it would be better to check the mime type or even better, check that it is indeed an image, by trying to make an image source out of it with a gd function. There's really no point to you not just sticking with file:"[^"]*" Also there are several things in there that you are escaping that you don't really need to escape. No harm I guess, but it makes it less readable.
-
$1 and $2 are populated from the captured matches from the pattern. putting (...) around something in a pattern captures what's inside it and you can use it as $1 etc.. in the replacement (note: these are not real variables. they are internal to preg_replace. So you can't turn around on the next line and do for instance echo $1;).
-
we are not here to write your code for you. Read the rules.
-
p.s.- your original problem is because your .* is greedy.
-
$string = '[img file:"image.jpg" alt:"alttext" /]'; $string = preg_replace('~\[img file:"([^"]*)" alt:"([^"]*)" /\]~','<img src="$1" alt="$2" />',$string); echo $string;
-
Crayon was here. ---------------> X
-
simple math... $percentyes = ($totalyes / $total) * 100; // percent of people who entered 'yes' How you populate those vars depends on how you are storing the data, as Mchl pointed out. As far as displaying it as a graph, you would have to dynamically build an image using gd library. Or you could just google for one of the millions of prefab scripts that already do that..
-
If you really want to hide the answers from the user, store it on the server in a file (chmoded or outside public directory) or database or inside server-side script and have your page make requests to the server to check the answer. You can reload the whole page or use ajax to send requests/get a response without reloading the whole page.
-
linking an external .js file would make it not show up in the main viewsource, but that would not stop someone from just going directly to the file. You could go a step further and change the chmod on the .js file or move it out of a public directory to not be accessible by the user, but the code still needs to be sent to the browser in order to work. All the user would have to do is use any number of a million addons out there to access it. So the bottom line is no, there is no way to hide js from a user.
-
document.getElementById('answer').value = "";
-
also fyi there is no way to "hide" your answers with javascript. It's there in the viewsource for all to see. Even if you encrypt it, your js would have to decrypt it at some point in time and all of that would be there too.
-
Do you find Freelancing to be worthwhile work?
.josh replied to freelancef2's topic in Miscellaneous
I enjoy doing freelance work on the side, but not as a main source of income. Not enough stability for me. And btw, being a freelancer does not mean being your own boss. You just have more control over what you will/won't do, but at the end of the day, the client is the boss. -
I'm curious how you would eyeball whether the files are "hacker" files or not... plan on just looking at the filenames and seeing if there are files in there that don't match a specific naming convention? Would be way faster to just write a quick program for that... but that really only weeds out "hacker" files that are foolish enough to not follow naming conventions...
-
so..you know how to pull data from a database and display it but you can't figure out how to make a simple counting variable? $count = 1; while (...) { echo $count; $count++; }
-
In case you were wondering about the error, preg_replace (and pretty much every other regex function in existence) expects delimiters to be put around the pattern, so that the engine knows what the start and end of the pattern is. $search = array( '~<~', '~>~', There are several different chars that can be used. Some of the more popular ones are /../ !..! #..# ~...~ You can even do <...> (notice it's open/close not open/open, in this case). Which is where your specific error comes into play. It saw the < and interpreted it as your opening delimiter instead of what you were wanting to match, saw no pattern after it (which is fine, you don't *need* a pattern but what's the point of regex without one...), and no closing delimiter of > to match the initial <.
-
sarchasm ftw
-
You already made a thread about this. Please do not make multiple threads asking the same thing. And btw, in case you failed to notice, you seem to be getting the same answers here as your other thread. Which means the real problem is that you are either not implementing these solutions properly or else you are not properly explaining the situation. If you decide to post more info about your situation, actual context, etc.. do it in the thread you started first. Thread closed.
-
what? I thought MS made installing their OS easier than ever. All you have to do is keep pressing the next button until you get the the finish button, and boom, your done!
-
if the lowest level of granularity are those achievement names, then sure, what you are currently doing would be okay. But if each of those achievements have their own attributes, then you should probably make a column called 'achievement_name' and columns for each attribute (and another column linking each row to specific user, like user_id or whatever).
-
well the point of a database in general is to have data stored in as much of a granulated way as possible. So when you are combining multiple values into a single cell, at best, you are making it harder on yourself to perform efficient queries, at worst, making some queries impossible. Take for instance the following: someColumn: animal:monkey animal:bat animal:mouse animal:snake animal:turtle plant:apple plant:banana plant:cucumber plant:rose plant:daisy So you have this column called someColumn If you wanted to find out all the rows that were plants, you would have to write a query returning everything that is a plant by doing something simple like this (or something similar with substr): select someColumn from table where someColumn like 'plant:%' it would be more efficient to have that stuff as two columns, like so: type someColumn: animal monkey animal bat animal mouse animal snake animal turtle plant apple plant banana plant cucumber plant rose plant daisy and did this: select someColumn from table where type = 'plant' On the surface, that doesn't seem like a big deal. Either way, both are relatively simple queries. But let's say you had a larger depth like so: animal:mammal:monkey animal:mammal:bat animal:mammal:mouse animal:reptile:snake animal:reptile:turtle plant:tree:fruit:red:apple plant:tree:fruit:yellow:banana plant:vine:green:cucumber plant:flower:red:rose plant:flower:white:daisy Now you are restricting yourself, because the different "levels" or "categories" suddenly become arbitrary. 3rd level animal may or may not have anything to do with 3rd level plant. Or even within 3rd level of plants, things may or may not have anything to do with each other at that level. It's all arbitrary. There's no way to "label" or categorize each level so you know which ones line up with which. That's what separating them into columns or even whole other tables are for. This may or may not apply to your specific circumstance. Just saying, in general, be weary of putting multiple values in the same cell like that.
-
it's not that those functions are bad or nothin', but just saying, if you find yourself storing info in a db like that, then imo first thing you should do is sit down and rethink your db structure.
-
if you're really think the best route to go is this... serialize unserialize
-
[SOLVED] Compare two ints for equality, without comparison operators.
.josh replied to FWDrew's topic in PHP Coding Help
yeah...I meant to also post on that...just cut to the chase and do $int_array = array($int_one,$int_two); -
[SOLVED] Compare two ints for equality, without comparison operators.
.josh replied to FWDrew's topic in PHP Coding Help
function int_equal_check($one,$two) { if (strcmp($one,$two)) return false; return true; } function int_equal_check($one,$two) { if (bccomp($one,$two)) return false; return true; } function int_equal_check($one,$two) { if (gmp_cmp($one,$two)) return false; return true; } function int_equal_check($one,$two) { if (preg_match("~^{$one}$~",$two)) return true; return false; } man I could go on all night... (edit: fixed regex pattern forgot start/end)