-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
to be clear, the problem is your quotes aren't lined up right. You start off with single quote, so if you have single quote as part of the value you need to escape it (prefix with a backslash) so that php knows you want to use a literal quote as part of the value instead of closing the string.
-
compare the current category name with the previous category name and only output if it changes... // example loop while ($row = mysql_fetch_row($result)) { if ($row['category_name'] != $previous_category_name) { // echo category name } // echo sub stuff $previous_category_name = $row['category_name']; }
-
A lot of times a script will have a "config" or "settings" variabe/object, or also a callback function that the script first calls or looks at when it runs, etc.. it's arbitrary, which is why you need to read the instructions that come with the script. For instance, if you have an image rotation script and the script works by updating an image tag with a new image src url, the script may allow you to specify the id attribute of the image tag and a list of URLs to rotate through, so it knows what image tag on the page to target and what images to display. init itself is not a special function. It is an arbitrarily named regular every day function just like any other javascript function. People just commonly use init as a naming convention specifically, because it is short, descriptive and intuitive in purpose.
-
Unfortunately the more time we give, the greater chance there is of people retroactively deleting their posts because they don't like leaving "I'm asking noob question" paper trails. And since the point of this site is to provide a resource and help people learn, we don't allow for it. But then at the other end of the spectrum we have people who legitimately want to edit their posts for things like what you mentioned.. so it's a balancing act. We've experimented with shorter edit windows and longer edit windows and so far where it is currently at seems like a nice warm butter zone (though for sure, there is no perfect spot). If you find yourself in that situation feel free to report your post and staff can edit it for you.
-
JavaScript function similar to PHP's include()?
.josh replied to melting_dog's topic in Javascript Help
you can make an ajax request, as long as the file is on the same domain as the page requesting it -
You found that code from google? How is that relevant to your code? How does the user login? do you already have a script for that, which works? If so, there should be a session variable with the info for you to use, or else a session variable with an id associated to the user, for you to query your database for the user's name. I'm starting to get the impression you have some 3rd party script you are trying to tweak...is this the case?
-
Where is the user name coming from? It *looks* like maybe you want: $user = $_GET['user_login']; header( "Location: http://www.mydomain.com/{$user}-manager" ) ; exit(); This assumes that you are receiving the user_login from a GET request like www.yoursite.com/thescriptabove.php?user_login=someuser and it will redirect you to for example: http://www.mydomain.com/someuser-manager
-
Yes, it goes in order. You have to first disallow everything and then allow the exceptions. Also dunno if you know or not but the crawlers don't have to obey the rules of robots.txt. Most major crawlers respect the rules but they don't *have* to and you shouldn't rely on robots.txt for other random bots/crawlers out there. Hell I personally don't really rely on it even for the major crawlers. Who knows when their policy might change. Better to look at the headers server-side and do something there. But even then that doesn't stop someone from faking headers. Anyways...
-
In my job, I do a lot of QA/Testing of websites. Many times I need certain things, for instance, I may need a dummy email address so I can go through a registration form. This has led me to create a little script that helps make my job easier. For example, one of the things my script does is it generates a timestamp based throwaway email address (and I have a filter setup to redirect to a specific qa email address if it is one of the generated email addresses, so that I can do things like validate email address to complete registration on a site if I need to go that far). My script also gives ability to save the generated email address along with other notes (like URL of form, password used etc..) for reference if I need it. Other things I have is a timestamp/datestring converter. Basically just put in a timestamp and it converts to datestring and visa versa. I also have a textarea where you can put in some random string and do things to it, like count the length of the string, truncate it to n chars, encode/decode, upper case, lowercase, convert from bin/hex/dec, md5 it, etc... Anyways, not really trying to advertise a script or nothin', just trying to give you an idea of what I mean by a "qa/test" script, so that I can ask the following: do you have any scripts like this, that you use for random things during your coding efforts? And if so, what kind of cool things does it do?
-
One of these (.php array) things is not like the other... but why?
.josh replied to Mavent's topic in PHP Coding Help
There is nothing wrong with the code you posted, your error is elsewhere. Or else the code you posted differs from the code you're running. -
Math works the same way here as it does on paper...technically in this case you don't even need to wrap anything in parens (though I usually do for better readability)...order of operations will have the division happen first...
-
I have a sneaking suspicion when OP refers to "header" he is talking about html content(like different top of the page menu/links), not http request/response headers.
-
echo just outputs literal strings (or parsed variables if in double quote). If you are wanting to execute/output the content of those scripts then you need to use include or require instead of echo.
-
PHP Deprecated: Function ereg_replace() is deprecated in
.josh replied to rastaman46's topic in Regex Help
Your first line of code has a / right after the opening ", and right before the closing ". How...HOW did you translate that to using a backslash as the opening delimiter, and putting the closing delimiter somewhere before your pattern ends? Man, you are making this WAY harder than it needs to be....I'm being serious here, not mean..if this is seriously too hard for you to understand, then you need to find another hobby besides coding, because this is NOT coding, this is copy and paste. If you cannot understand basic copy and paste, then you cannot even begin to code. -
PHP Deprecated: Function ereg_replace() is deprecated in
.josh replied to rastaman46's topic in Regex Help
before... $pageed = ereg_replace(".*<$loop[$y]>", "", $page); after: $pageed = preg_replace("/.*\<{$loop[$y]}\>/", "", $page); before... $$scphp = ereg_replace("</$loop[$y]>.*", "", $pageed); after: ??? You have two lines of code that have the same problem: using a deprecated function. You have been told what you need to change, and someone even did the first line for you, so all you need to do is follow the instructions, or failing that, look at the changes in your first line and apply the same changes to the second line. Exactly what part of this are you having trouble with? Because at this point, this isn't even about coding, it's simple clerical skills...find and copy... -
array_search() searches the array values and returns the key an array is array(key => value). As far as the Notice...maybe you snagged the code before I edited it..I forgot to add the 2nd param when I first posted it.
-
what does nr mean?
-
First off, in your conditions, = is the assignment operator, whereas == is the equality operator...you should be using == in your conditions. But anyways, you can cut all those conditions out by using an array: $catIDs = array( 3 => "Automotive", 4 => "Business", // etc... ); $catid = array_search(trim($_POST['catid']), $catIDs); echo $catid; array_search will search the array and return the key (like 3,4, etc..) or if value not found, it will return boolean false.
-
check if it isset before checking the value.
-
foreach ($array["MPI"] as $key => &$value) { foreach ($value as $k => &$v) { if ( isset($array["Competitive set"][$key][$k]['data'])&&isset($array["Test"][$key][$k]['data']) ) { $v['data'] = ( $array["Competitive set"][$key][$k]['data'] / $array["Test"][$key][$k]['data'] ) * 100; } } }
-
It depends on your question...in general, if you have a question about php code (and it is your code, not a 3rd party script) or how a php function works etc.. then this is the right place, yes. Try to figure out what your problem is about. Then read the forum descriptions.
-
What timezone is your server located in? What is the server time zone the server goes by?
-
PHP Deprecated: Function ereg_replace() is deprecated in
.josh replied to rastaman46's topic in Regex Help
You apply the same principle you just learned to this line...use the gray matter between your ears bro... -
PHP Deprecated: Function ereg_replace() is deprecated in
.josh replied to rastaman46's topic in Regex Help
Php doesn't have a g modifier for pcre functions. preg_replace() by default performs global search and replace, and if you want to limit it there's an optional argument to pass to it