-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
You didn't actually post your form code, so I can't tell you whether or not your javascript looks okay or not. But in general, a request only submits checkboxes that are checked. Assuming your actual ajax request/response works, you can test it by just doing a print_r($_POST); to see the posted vars output. What the format looks like, depends on how you named your checkboxes. One thing I do notice wrong with your php script though is that you need to have a session_start() call before you make use of session vars (and before anything is actually output). Beyond that, was there some other particular issue you are stuck on? I'm afraid there's not really much I can say.. your question is too broad for the code you posted.
-
Okay well, if you don't think so, then whatever floats your boat. I happen to work in the analytics/ppc/seo industry, so just giving you my PoV. Good luck.
-
First off you should know that swapping out content like this is a form of content stuffing, is considered blackhat seo tactics, is against Google's ToS and you will be blacklisted for it. If this somehow doesn't deter you from doing it, then here's your next problem: You can't do this with an iframe hosted on another site. This is considered cross site scripting (XSS) (read up on same domain origin policy). The only way to do what you are wanting to do is to use something like file_get_contents or the cURL library and retrieve the contents of the page, use str_replace to swap out the content, and then output it on your own page, not hosted externally in iframe.
-
Pick a pagination tut that has the non-numerical links and just remove the loop that outputs the linked numbers. For example, on this really old pagination tut I made: http://www.phpfreaks.com/tutorial/basic-pagination just remove the code block with this comment header: // loop to show links to range of pages around current page Though as a sidenote, and this is totally IMO.. I hate pagination links that don't have the full controls.
-
// 1 or more numbers following if ( preg_match('~^A[0-9]+$~',$string) ) { // true } // 2 or more numbers following if ( preg_match('~^A[0-9]{2,}$~',$string) ) { // true } // exactly 7 numbers following if ( preg_match('~^A[0-9]{7}$~',$string) ) { // true } // between 5 and 7 numbers following if ( preg_match('~^A[0-9]{5,7}$~',$string) ) { // true }
-
you are on the right track as far as wrapping it in quotes. However, your overall quotes for the query are single quotes. php variables are not parsed inside single quotes. Make your outer quotes double and your inner quotes single, or else break out of the quotes and concatenate
-
untested... echo "<table border='1'>"; foreach ($mainArray as $i => $array) { if ( isset($mainArray[$i-1]) && ($mainArray[$i-i]['product']['name'] != $array['product']['name']) ) echo "</table><table border='1'>"; echo "<tr><td>".implode("</td><td>",$array['product'])."</td></tr>"; } echo "</table>";
-
Deprecated: Function ereg_replace() is deprecated in....
.josh replied to ShivaGupta's topic in Regex Help
There is a pinned thread in this forum, called "ereg and 'deprecated' error". It is literally right above your thread. You might even get confused and think it's YOUR thread, being named similar and all. Can you at least TRY to look, before asking? -
This, almost without fail, leads to wasting both your time and our time. Especially when it comes to regex. What may work in the "simplified" scenario may not work in the bigger picture. Always explain the full, actual problem. But in any case, it sounds like what you may be looking for is a negative lookahead. For example: $s1 = 'this is the other version new'; $s2 = 'this is the other version old'; preg_match('~(?!.*new)this is the other version.*~',$s1,$m); // output: no match preg_match('~(?!.*new)this is the other version.*~',$s2,$m); /* output: Array ( [0] => this is the other version old ) */ (?!pattern) is the syntax for a negative lookahead. The important thing to understand is that it is a zero-width assertion. This means that when something matches, the engine doesn't actually consume what it matches; it doesn't move the pointer forward. So nothing it matches will show in the returned $m array. Hence the name lookahead. It's like if you are walking in the woods and you have a walking stick and you poke at the ground ahead of you to make sure there aren't any snakes before you take another step forward - poking the ground in front of you gives you insight on whether or not you should move forward, but it doesn't itself move you forward. (?!.*new) uses a basic .* match all to cover the whole string and new looks for the literal substring "new". So this is saying "look ahead in this string to see if 'new' is NOT in there somewhere - IOW "see if this pattern does NOT match - and if true (it does not match), proceed with the rest of the pattern. Then the rest of the pattern is pretty basic: match the literal phrase followed by a .* to match the " old" after it.
-
Onclick event calling php function from generated code
.josh replied to krkec's topic in PHP Coding Help
There are literally thousands of AJAX tutorials out there on the web; it is a very common thing. Most all of them involve pulling and returning info from a database when something is clicked or changed (e.g. auto-complete search, dynamic multiple dropdowns, etc.). They are all the same principle. Just google "php ajax tutorial". If you get stuck at something specific, feel free to ask for help. -
Regex to find Variables Names & Function Names inside PHP Source File
.josh replied to tserfer's topic in Regex Help
I too was very bored, so here is some code to parse token_get_all for them. I threw in class names too.. those should arguably be included. I also threw in constants. Now, this will only return php-defined constants (like `PHP_EOL`). Since the code isn't actually being evaluated, there's no way to check if it's a constant with defined(). Which means you'd have to kinda determine for yourself if it's a constant, based on the context. Which isn't as easy as it sounds. Especially if the code has syntax errors. I'm not going to outright say it's impossible but my attention span only goes so far when I'm doing something for free $namedTokens = array( 'VARIABLE' => array(), 'USER_FUNCTION' => array(), 'CLASS' => array(), 'PHP_FUNCTION' => array(), 'PHP_CONSTANT' => array() ); foreach ($tokens as $key => $token) { if (is_array($token) && isset($token[0]) && is_int($token[0])) { $tn = token_name($token[0]); switch ($tn) { case 'T_VARIABLE' : if (!in_array($token[1], $namedTokens['VARIABLE'])) $namedTokens['VARIABLE'][] = $token[1]; break; case 'T_FUNCTION' : case 'T_CLASS' : if (isset($tokens[$key+1]) && is_array($tokens[$key+1])&& isset($tokens[$key+1][0])&& token_name($tokens[$key+1][0])=='T_WHITESPACE') if (isset($tokens[$key+2]) && is_array($tokens[$key+2])&& isset($tokens[$key+2][0])&& token_name($tokens[$key+2][0])=='T_STRING') { switch ($tn) { case 'T_FUNCTION' : $nt = 'USER_FUNCTION'; break; case 'T_CLASS' : $nt = 'CLASS'; break; } $namedTokens[$nt][] = $tokens[$key+2][1]; } break; case 'T_STRING' : /* php native function */ if (function_exists($token[1])&&!in_array($token[1], $namedTokens['PHP_FUNCTION'])) $namedTokens['PHP_FUNCTION'][] = $token[1]; /* php native constants*/ if (defined($token[1])&&!in_array($token[1], $namedTokens['PHP_CONSTANT'])) $namedTokens['PHP_CONSTANT'][] = $token[1]; break; } // end switch } // end if } // end foreach // example: print_r($namedTokens); -
Onclick event calling php function from generated code
.josh replied to krkec's topic in PHP Coding Help
you can't directly call a php function from javascript. php is server-side. javascript is client-side. In order to do this, you need to have js do an ajax request to a php script that can run the function and return results, and then use javascript to show updated info or whatever. -
Well good luck with that. Feel free to post any specific questions if you get stuck somewhere.
-
also... unless you have some kind of custom coding.. $this->db->query() will almost certainly be returning a result source, not an array of values to pass to list. You will probably need to use something like $this->db->fetch_array() or similar.
-
what was the problem? I was gonna next suggest image caching..
-
var declares the variable for the current scope. The main purpose of doing it is to ensure you are not overwriting a variable in a higher scope. Example: var foo = 'bar'; function doSomething() { foo = 'blah'; } console.log(foo); doSomething(); console.log(foo); output: bar blah In this example, foo is first declared in the global scope. Then within function doSomething(), the variable foo is assigned another value. Because foo was declared in the global scope, and there is not a var prefix in the function, javascript will assign the new value "blah" to that global variable. This is because javascript sees that you are doing something with a variable and moves up the scope chain to find where that variable was declared, and reference it when it finds it. Now, if I had NOT declared foo in the higher scope, javascript would have implicitly declared it within the function's scope, even without the var prefix. But this is not something you should depend on or code for. You should always declare you locally scoped variables, to avoid the dangers of overwriting variables in a higher scope. I have seen this happen time and time again with "throwaway/temp" local variables. For example, someone just picks a random variable to use as an incrementer for a loop, but doesn't declare it.. only to find out later that it overwrote some 3rd party app's namespace in the global scope. And this happens more often than you think, because 3rd party vendors are notorious for using short namespaces to condense their code as much as possible, and coders are notorious for using short namespaces for "throwaway/temp" vars. For example, Adobe Marketing Analytics is an enterprise level site/visitor tracking solution (it's like Google Analytics but has a LOT more bells and whistles but costs a LOT of money). It's default namespace is s. And until relatively recently, it didn't have an easy way to change that namespace. Now consider this code: <script type='text/javascript'> function getPageName() { s=location.pathname.replace(/^\/|\/$/g,'').split('/').pop(); return s; } </script> <!-- watered down version of Adobe code --> <script type='text/javascript' src='s_code.js'></script> <script type='text/javascript'> s.pageName=getPageName(); s.prop1='en'; s.t(); </script> All "that could have been written better" responses aside, this demonstrates the problem of namespace overwriting. s is declared within s_code.js and is Adobe's object namespace. Some custom tracking variables are then set, and s.t() is the "trigger" function that makes the tracking request happen. But see how we delegate popping s.pageName to some function (which is pretty common). Because function getPageName() did not first declare s locally, javascript will overwrite s in the global scope, and you will end up getting a javascript error from the rest of the code which attempts to use s as an object with established properties and methods. A more realistic example (that I have seen happen quite a number of times) is when the Adobe library script is included in the head tag, and the custom code and trigger is placed on the bottom of the page before closing body tag (again, pretty common setup). That leaves a whole lot of space inbetween for some other random js snippet or 3rd party library to be placed and accidentally overwrite the s namespace. The most common thing I've seen is js loaded script includes, which look something like this: (function() { var s = document.createElement('script'); s.type = "text/javascript"; s.src = "https://www.site.com/script.js"; var st = document.getElementsByTagName('script')[0]; st.parentNode.insertBefore(s, st); })(); This is more or less the standard way of using js to include a script (unless you are using a js library like jQuery). This example is fine, because variables are declared and there's closure and all that. However, I have seen some people not wrap it in an anonymous function, and I have seen some people not declare their variables before assigning to them. And s is a common var coders use in this scenario, since it's short for "script". You don't have to use it.. but it's a common convention to name variables after what they stand for. Anyways, TL:DR; version: Unless you are intentionally referencing a higher scoped variable, always make sure to declare the local scoped vars you use, to make sure you don't accidentally overwrite some other higher scoped variable. Actually, it is a rare case in which it's a good idea to reference higher scoped variables in the first place. Ideally, you should be passing them to the function and returning the value. There are exceptions to this (e.g. referencing the window or document object), and also some cases where you're working with what you have and can't touch other code (the "lesser evil" scenarios), but usually you should avoid doing that.
-
well what I'm saying is $check = strpos($search, $log); you don't define $log anywhere.
-
i don't think it's the only problem but one thing I see is that $log is not defined when you are using it in your strpos
-
REST call to a URL list, return JSON values into a table
.josh replied to Svarog's topic in PHP Coding Help
Right.. you said you wanted that, and that's what I initially gave you. Then you said it wasn't right, and went on to explain other columns you didn't mention before, and how it should be dynamic. So I gave you that. Now you are saying no, that wasn't what you wanted, that you just wanted 4 columns. So why did you tell me my first solution was wrong then? -
REST call to a URL list, return JSON values into a table
.josh replied to Svarog's topic in PHP Coding Help
are you kidding me? Seriously?? That's what I showed you in my first post.. all you had to do was just echo out the ones you wanted. But then you said that wasn't right, because: Which I took to mean that the columns needed to be dynamically generated based on the results. If you wanted to only echo out those for columns, why the hell did you even mention "PartID"? WHY ARE YOU WASTING MY TIME. $result = '[{"PartID":123,"Category":5,"PartNumber":1267,"Description":"blabla....","Status":"some status","Timestamp":"123456789","Datasheet":"some value"}]'; $data = json_decode($result, true); echo '<table border="1">'; echo '<tr><th>Description</th><th>Status</th><th>Timestamp</th><th>Datasheet</th></tr>'; foreach ($data as $jsons) { echo '<tr>'; echo '<td>' . $jsons['Description'] . '</td>'; echo '<td>' . $jsons['Status'] . '</td>'; echo '<td>' . $jsons['Timestamp'] . '</td>'; echo '<td>' . $jsons['Datasheet'] . '</td>'; echo '</tr>'; } echo '</table>'; -
REST call to a URL list, return JSON values into a table
.josh replied to Svarog's topic in PHP Coding Help
Okay so actually, I assumed I couldn't do the curl myself because I needed an actual value for "X-Auth-Token: Example". Turns out I don't. I'm kind of curious how your script is even working. First off, this line is bad syntax, there shouldn't be braces around that 3rd arg like that. curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Auth-Token: Example']); 2nd, you aren't setting curl to put the results in $result. by default it outputs the results to the screen, so you should already be seeing a dump of the results on the page.. in order to have it put into $result, you need to have this: curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 3rd, it looks like it's returning a lot of data and timing out before 10s limit you set on it, which is resulting in malformed json string. IOW you need to up that timeout limit to handle the full results. 4th, you did not accurately present the format. It looks like from the data that is returned, each row doesn't just have a simple "header":"value" format. Some of the headers themselves have an array of results. I'm talking about the "Specs" column specifically. So how exactly do you want that to be presented? If you want me to continue helping, you need to make a better effort in explaining exactly what you want. -
REST call to a URL list, return JSON values into a table
.josh replied to Svarog's topic in PHP Coding Help
You saw for yourself it worked with the example json. So either what is returned isn't really json or it's somehow malformed or not in the same format as the example you showed or something. Anyways, how am i supposed to figure out what's wrong when I can't see it? -
REST call to a URL list, return JSON values into a table
.josh replied to Svarog's topic in PHP Coding Help
okay, well then that means your curl request isn't returning expected results. After $data = json_decode($result, true); echo "<pre>"; print_r($data); exit(); What does that output?