premiso
Members-
Posts
6,951 -
Joined
-
Last visited
-
Days Won
2
Everything posted by premiso
-
[SOLVED] How to handle Image extensions(JPG/jpg)
premiso replied to divadiva's topic in PHP Coding Help
Do you upload these images? Why not strtolower the image file names, like you do the DB? The only other way to work around this is have all possible cases in an array and loop through with file_exists. Which I highly suggest against. Put the right file name in the DB and you will be fine. EDIT: And given that you are using the ASP tags, I will take it that you are used to working on a windows system and have switched to a *nix system. If this is the case that is problem, *nix is case SenSitIve where as windows is case insensitive. -
I never fully understood OOP until I got hired on by a private guy and coded, school teaches you nothing about proper usage. The hard thing was, that was coding in C# and then trying to go to PHP and mimic behavior was frustrating cause PHP 4 sucked at OOP. PHP 5 was a huge breath of fresh air though! EDIT: Just a side note, I still have problems with the proper methodology of OOP, it is a tough concept to grasp. Best way is to write an outline of your plan I have found, at least that helps me.
-
I generally separate lists in my db using a , especially ones I know will not contain other commas, then explode at that. Makes it easier and you know what to explode it and know that it should work each time. But that is just me.
-
Use a checkbox next to the image, if the checkbox is checked that image value gets passed via a form in HTML. Then you would access which was chosen via $_POST (if the form was posted) or $_GET if the form was sent via GET (Post is better for this scenario fyi). I do not think you can just click on an image and have that be selected. If it can you would be using javascript to create an html element on the page dynamically to show that. In which case this is a javascript issue, not php.
-
Look into .htaccess, you can do a 301 redirect or using mod_rewrite to accomplish this.
-
You're using variables inside single quotes... echo "<a href=\"javascript:poptastic('http://www.website.com/profile.php?playername={$url}');\">{$name}</a>"; Yea I feel like a tard. I forgot that the { and } do not parse out under single quotes.
-
I do not see them being split by a newline, just by a space. If that is correct, this should work: function badWords($clean) { global $SystemSettings; if(!empty($SystemSettings['censored_words'])) { $words = explode(" ", $SystemSettings['censored_words']); $clean = str_replace($words, $SystemSettings['filtered_outcome'], $clean); } return $clean; } If that still does not work, lets try this for kicks function badWords($clean) { global $SystemSettings; if(!empty($SystemSettings['censored_words'])) { $words = array("word1", "word2"); $clean = str_replace($words, $SystemSettings['filtered_outcome'], $clean); } return $clean; } And if you are using php 5 or greater use str_ireplace instead. So it is a case-insensitive search.
-
Gotcha. Could that be causing the issue? Other than that, I am not sure how IIS really works and maybe it changes scopes of stuff, I dunno. I would make it a constant anyways, just makes everything that much easier.
-
Posting the error and line may help out a bit more. Given the above, I do not see a php Syntax error.
-
Are you sure that censored_words is actually being populated right? Can you post a sample of an echo'd out version of that?
-
Probably not, but still good practice. Makes debugging easier imo. Just noticed he is also using: print_r($GET) Instead of print_r($_GET); Which may print the variables.
-
ok that sounds like an incredible pain, so... i was thinking that i could just add something like $siteRoot = "C:\inetpub\websites\sitename" to a common.php file. and then just include common.php in every page. i was already including common.php in every page for another reason so i thought this woudl be easy. well the line i am having problems with (the one opening the xml file) in in siteroot\includes\functions.php. and functions.php could be called from any page anywhere in the site. si i will have a problem is i have to include common.php in functions.php. so i was thinking i could just include common.php in any page the includes functions.php (as long as in included common.php before i include functions.php. but for some reason when i try that, it says Undefined variable: siteRoot in C:\...\functions.php wouldnt functions.php be able to grab the $siteRoot variable from the include of common.php on the calling page (siteroot\index.php)?? For IIS it is probably a pain, for Apache it is actually really really simple and totally worth it for not having to change the server configuration file anytime you want to change servers. I think your logic is not seeing the total picture. I could just be gathering the wrong conclusion out of this, so here is what I think you are trying to figure out: You have multiple sites on your box. You want to be able to switch from siteA which is located at c:\wwwroot\siteA to siteB which is located at c:\wwwroot\siteB without having to modify the configuration file and change the document root each time. Right? If that is right, then doing that in commons.php will not help you, unless each page of your script goes and calls that identical page for siteB and includes it. Due to the simple fact that siteA files are probably not the same as siteB files. Unless SiteA is just a mirror of siteB, in which case your logic may work. If that is not the case, sorry man, but the work around is not that simple. If my impression was wrong, totally disregard everything I posted. To include something no matter what the path is, $_SERVER['DOCUMENT_ROOT'] is the key, just remember you still have to define /path/after/root/to/file to get it to include right. As for the $siteRoot not being defined, are you sure you are including the new version of the commons.php? EDIT: Are you also sure you are not trying to use $siteRoot inside a function or class? If you plan to do that you need to use define and make SITEROOT a constant to have a global scope.
-
And thinking about it: function badWords($clean) { global $SystemSettings; if(!empty($SystemSettings['censored_words'])) { $words = explode("\n", $SystemSettings['censored_words']); $clean = str_replace($words, $SystemSettings['filtered_outcome'], $clean); } return $clean; } Should work without the foreach.
-
$words = explode("\\n", $SystemSettings['censored_words']); Shoudd be: $words = explode("\n", $SystemSettings['censored_words']); You do not need to escape the \ as the \n is it's own character. And use str_replace over ereg_replace for simple replacements like you have.
-
Change all instances of <?echo($data['customer_id']);?> To be <?php echo ($data['customer_id']); ?> Spacing will not kill ya, and use <?php over <? cause the short tags can be turned off.
-
while($row = mysql_fetch_array($result)) { $name = $row['name']; $url = urlencode($name); echo '<a href="javascript:poptastic(\'http://www.website.com/profile.php?playername={$url}\');">{$name}</a>'; } Should solve your syntax issue.
-
Upon calling back $_GET['name'] you would need to use urldecode, but as gevens pointed outyou have a syntax error and it is not in the 1 line of code you posted.
-
If it were Apache this would actually be really easy. But maybe you can google Virtual Hosts for IIS, then you would need to modify your HOSTS file via c:/Windows/System32/Drivers/etc/hosts And add in different host names, like 127.0.0.1 site1.dev Then in your virtual host add site1.dev so that when it is called on your local server it will goto that site. I hate IIS, but maybe you can do some searching and solve this problem.
-
Where does this data come from? A database? You should sort that by Year DESC it is better to sort data where it is easily sorted. Doing that you can create this array just like you have it with no problems.
-
The function has to return a value class myClass{ function functionC() { return "Return This!"; } } $class = new myClass(); $return = $class->functionC(); echo $return; If it does not return a value you will not be able to do that, unless the value is stored as a public property.
-
Why are you echoing it the same line...not sure if that is kosher, but this will solve your woes $_SESSION['totalcost'] = $_SESSION['totalcost']+$costofitem; A bit more code, but it works, I think the + would need to be next to the equals for it to work the other way: $_SESSION['totalcost'] += $costofitem; I am not sure if it is += or =+ but yea. Rinse and repeat for each time you need that done. Edit: Check out the Assignment operators for info on proper usage.
-
Thanks for the help. I checked the phpinfo and I think I'm ok with the memory limit (16mb). But my max_execution_time is 30 secs. I did a test and my script seemed to last ~ 40 secs so I bet that's the problem. Should I change the time limit in the code itself, or in a configuration file? I have read about php.ini files but I don't know that much about it. The script itself is fine.
-
array_shift
-
You need to check your memory_limit and your time_limit. set_time_limit will help you to remove the max execution time, then the ini_set method to set the max_memory_usage or something along those lines. Although it should be defaulted to 16MB. You may do a phpinfo and check what the memory limit is being set at, as dreamhost may set it to be 5MB.
-
$HTTP_FILES_VARS should be $_FILES.