Search Results

Search found 37 results on 2 pages for 'sologhost'.

Page 2/2 | < Previous Page | 1 2 

  • How to get the Entire Function from a file

    - by SoLoGHoST
    Ok, I'm reading through a file now, line by line. I know each functions name in the file, since it is defined elsewhere in an XML document. That is what should be this: function function_name Where function_name is the name of the function. I get all of the function definitions from an XML document that I already have put into an array of function names, and I need to grab just those functions from the php file. And rebuild that php file so that it only has those functions in it. That is to say, if a php file has more functions than what is defined in the XML tag, than I need to strip out those functions, and rewrite the .php file with only the functions that the user specified in the XML file. So, the dilemma I face is how to determine the END of a function reading line by line, and I'm aware that functions can have function within them. So I don't want to remove the functions within them. Just functions that are standalone and aren't defined within the accompanying XML file. Any ideas on how to do this?? Thanks :)

    Read the article

  • create_function with default parameter values?

    - by SoLoGHoST
    Ok, I'm looking into using create_function for what I need to do, and I don't see a way to define default parameter values with it. Is this possible? If so, what would be the best approach for inputting the params into the create_function function in php? Perhaps using addslashes? Well, for example, I have a function like so: function testing($param1 = 'blah', $param2 = array()) { if($param1 == 'blah') return $param1 else { $notblah = ''; if (count($param2) >= 1) { foreach($param2 as $param) $notblah .= $param; return $notblah; } else return 'empty'; } } Ok, so how would I use create_function to do the same thing, adding the parameters and their default values? The thing is, the parameters are coming from a TEXT file, as well as the function itself. So, wondering on the best approach for this using create_function and how exactly the string should be parsed. Thanks :)

    Read the article

  • Searching within an array of strings...

    - by SoLoGHoST
    Ok, I'm feeling retarded here, I have a string like so: $string = 'function module_testing{'; or it could be like this: $string = 'function module_testing'; And than I have an array of strings like so: $string_array = array('module_testing', 'another_function', 'and_another_function'); Now, is there some sort of preg_match that I can do to test if any of the $string_array values are found within the $string string at any given position? So in this situation, there would be a match. Or is there a better way to do this? I can't use in_array since it's not an exact match, and I'd rather not do a foreach loop on it if I can help it, since it's already in a while loop. Thanks :)

    Read the article

  • Howto open a file and remove the last line?

    - by sologhost
    I am looking to open up a file, grab the last line in the file where the line = "?", which is the closing tag for a php document. Than I am wanting to append data into it and add back in the "?" to the very last line. I've been trying a few approaches, but I'm not having any luck. Here's what I got so far, as I am reading from a zip file. Though I know this is all wrong, just needing some help with this please... // Open for reading is all we can do with zips and is all we need. if (zip_entry_open($zipOpen, $zipFile, "r")) { $fstream = zip_entry_read($zipFile, zip_entry_filesize($zipFile)); $fp = fopen($curr_lang_file, 'r+b'); while (!feof($fp)) { $output = fgets($fp, 16384); if (trim($output) == '?>') break; fwrite($fp, $output); } fclose($fp); file_put_contents($curr_lang_file, $fstream, FILE_APPEND); } $curr_lang_file is a filepath string to the actual file that needs to have the fstream appended to it, but after we remove the last line that equals '?'

    Read the article

  • SQL: Using a CASE Statement to update 1000 rows at once

    - by SoLoGHoST
    Ok, I would like to use a CASE STATEMENT for this, but I am lost with this. Basically, I need to update a ton of rows, but just on the "position" column. I need to update all "position" values from 0 - count(position) for each id_layout_position column per id_layout column. OK, here is a pic of what the table looks like: Now let's say I delete the circled row, this will remove position = 2 and give me: 0, 1, 3, 5, 6, 7, and 4. But I want to add something at the end now and make sure that it has the last possible position, but the positions are already messed up, so I need to reorder them like so before I insert the new row: 0, 1, 2, 3, 4, 5, 6. But it must be ordered by lowest first. So 0 stays at 0, 1 stays at 1, 3 gets changed to 2, the 4 at the end gets changed to a 3, 5 gets changed to 4, 6 gets changed to 5, and 7 gets changed to 6. Hopefully you guys get the picture now. I'm completely lost here. Also, note, this table is tiny compared to how fast it can grow in size, so it needs to be able to do this FAST, thus I was thinking on the CASE STATEMENT for an UPDATE QUERY. Here's what I got for a regular update, but I don't wanna throw this into a foreach loop, as it would take forever to do it. I'm using SMF (Simple Machines Forums), so it might look a little different, but the idea is the same, and CASE statements are supported... $smcFunc['db_query']('', ' UPDATE {db_prefix}dp_positions SET position = {int:position} WHERE id_layout_position = {int:id_layout_position} AND id_layout = {int:id_layout}', array( 'position' => $position++, 'id_layout_position' => (int) $id_layout_position, 'id_layout' => (int) $id_layout, ) ); Anyways, I need to apply some sort of CASE on this so that I can auto-increment by 1 all values that it finds and update to the next possible value. I know I'm doing this wrong, even in this QUERY. But I'm totally lost when it comes to CASES. Here's an example of a CASE being used within SMF, so you can see this and hopefully relate: $conditions = ''; foreach ($postgroups as $id => $min_posts) { $conditions .= ' WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id; $lastMin = $min_posts; } // A big fat CASE WHEN... END is faster than a zillion UPDATE's ;). $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET id_post_group = CASE ' . $conditions . ' ELSE 0 END' . ($parameter1 != null ? ' WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), array( 'members' => $parameter1, ) ); Before I do the update, I actually have a SELECT which throws everything I need into arrays like so: $disabled_sections = array(); $positions = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($disabled_sections[$row['id_group']][$row['id_layout']])) $disabled_sections[$row['id_group']][$row['id_layout']] = array( 'info' => $module_info[$name], 'id_layout_position' => $row['id_layout_position'] ); // Increment the positions... if (!is_null($row['position'])) { if (!isset($positions[$row['id_layout']][$row['id_layout_position']])) $positions[$row['id_layout']][$row['id_layout_position']] = 1; else $positions[$row['id_layout']][$row['id_layout_position']]++; } else $positions[$row['id_layout']][$row['id_layout_position']] = 0; } Thanks, I know if anyone can help me here it's definitely you guys and gals... Anyways, here is my question: How do I use a CASE statement in the first code example, so that I can update all of the rows in the position column from 0 - total # of rows found, that have that id_layout value and that id_layout_position value, and continue this for all different id_layout values in that table? Can I use the arrays above somehow? I'm sure I'll have to use the id_layout and id_layout_position values for this right? But how can I do this? Ok, guy, I get an error, saying "Hacking Attempt" with the following code: // Updating all positions in here. $smcFunc['db_query']('', ' SET @pos = 0; UPDATE {db_prefix}dp_positions SET position=@pos:=@pos+1 ORDER BY id_layout_position, position', array( ) ); Am I doing something wrong? Perhaps SMF has safeguards against this approach?? Perhaps I need to use a CASE STATEMENT instead?

    Read the article

  • SQL: Using a CASE Statement to update a 1000 rows at once, how??

    - by SoLoGHoST
    Ok, I would like to use a CASE STATEMENT for this, but I am lost with this. Basically, I need to update a ton of rows, but just on the "position" column. I need to update all "position" values from 0 - count(position) for each id_layout_position column per id_layout column. Here's what I got for a regular update, but I don't wanna throw this into a foreach loop, as it would take forever to do it. I'm using SMF (Simple Machines Forums), so it might look a little different, but the idea is the same, and CASE statements are supported... $smcFunc['db_query']('', ' UPDATE {db_prefix}dp_positions SET position = {int:position} WHERE id_layout_position = {int:id_layout_position} AND id_layout = {int:id_layout}', array( 'position' => $position++, 'id_layout_position' => (int) $id_layout_position, 'id_layout' => (int) $id_layout, ) ); Anyways, I need to apply some sort of CASE on this so that I can auto-increment by 1 all values that it finds and update to the next possible value. I know I'm doing this wrong, even in this QUERY. But I'm totally lost when it comes to CASES. Here's an example of a CASE being used within SMF, so you can see this and hopefully relate: $conditions = ''; foreach ($postgroups as $id => $min_posts) { $conditions .= ' WHEN posts >= ' . $min_posts . (!empty($lastMin) ? ' AND posts <= ' . $lastMin : '') . ' THEN ' . $id; $lastMin = $min_posts; } // A big fat CASE WHEN... END is faster than a zillion UPDATE's ;). $smcFunc['db_query']('', ' UPDATE {db_prefix}members SET id_post_group = CASE ' . $conditions . ' ELSE 0 END' . ($parameter1 != null ? ' WHERE ' . (is_array($parameter1) ? 'id_member IN ({array_int:members})' : 'id_member = {int:members}') : ''), array( 'members' => $parameter1, ) ); Before I do the update, I actually have a SELECT which throws everything I need into arrays like so: $disabled_sections = array(); $positions = array(); while ($row = $smcFunc['db_fetch_assoc']($request)) { if (!isset($disabled_sections[$row['id_group']][$row['id_layout']])) $disabled_sections[$row['id_group']][$row['id_layout']] = array( 'info' => $module_info[$name], 'id_layout_position' => $row['id_layout_position'] ); // Increment the positions... if (!is_null($row['position'])) { if (!isset($positions[$row['id_layout']][$row['id_layout_position']])) $positions[$row['id_layout']][$row['id_layout_position']] = 1; else $positions[$row['id_layout']][$row['id_layout_position']]++; } else $positions[$row['id_layout']][$row['id_layout_position']] = 0; } Thanks, I know if anyone can help me here it's definitely you guys and gals... Anyways, here is my question: How do I use a CASE statement in the first code example, so that I can update all of the rows in the position column from 0 - total # of rows found, that have that id_layout value and that id_layout_position value, and continue this for all different id_layout values in that table? Can I use the arrays above somehow? I'm sure I'll have to use the id_layout and id_layout_position values for this right? But how can I do this?

    Read the article

  • Content Types in browsers, can we use the Mime??

    - by SoLoGHoST
    Ok, I am wondering which mime types are dangerous in browsers? That is to say setting the Content Type to that mime type?? Which mime types, if any would pose a security risk?? I am noticing that many forum software, when uploading files, use the application/octet-stream for any files other than images and place that into the Content Type of the header. I am wondering why don't they place the actual mime-type instead into the Content Type? Are there security risks involved with this? So far I have used text/css, text/plain, audio/mpeg, and many others and haven't noticed any difference between application/octet-stream and these others. Does anyone out there know the exact difference, and what makes application/octet-stream any better, or any worse...to use for the Content Type?? Thank You :)

    Read the article

  • PHP: Fastest way possible to read contents of a file.

    - by SoLoGHoST
    Ok, I'm looking for the fastest possible way to read all of the contents of a file via php with a filepath on the server, also these files can be huge. So it's very important that it does a READ ONLY to it as fast as possible. Is reading it line by line faster than reading the entire contents? Though, I remember reading up on this some, that reading the entire contents can produce errors for huge files. Is this true?

    Read the article

  • How to localize numerals?

    - by SoLoGHoST
    Ok, I'm using mathematical equations to output numbers, though, I need this to be compatible for all languages. Currently, all language strings are within a php array called $txt, and each key of the array gets called for that language. I'm outputting the following: Column 1, Column 2, Column 3, and so on, as well as Row 1, Row 2, Row 3, and so on. The calculations are done via php and javascript, so I'm wondering on the best approach for how to support all languages for the numbers only. I don't do the translations, someone else does, but I need to be able to point it to, either the php variable $txt of where the language is defined, or, since the calculations are done via javascript also, I need to somehow store this in there. I'm thinking of storing something like this: // This part goes in the php language file. $txt['0'] = '0'; $txt['1'] = '1'; $txt['2'] = '2'; $txt['2'] = '3'; $txt['4'] = '4'; $txt['5'] = '5'; $txt['6'] = '6'; $txt['7'] = '7'; $txt['8'] = '8'; $txt['9'] = '9'; // This part goes in the php file that needs to call the numbers. echo '<script> var numtxts = new Array(); numtxts[0] = \'', $txt['0'], '\'; numtxts[1] = \'', $txt['1'], '\'; numtxts[2] = \'', $txt['2'], '\'; numtxts[3] = \'', $txt['3'], '\'; numtxts[4] = \'', $txt['4'], '\'; numtxts[5] = \'', $txt['5'], '\'; numtxts[6] = \'', $txt['6'], '\'; numtxts[7] = \'', $txt['7'], '\'; numtxts[8] = \'', $txt['8'], '\'; numtxts[9] = \'', $txt['9'], '\'; </script>'; And than in the javascript function it could grab the correct string for each number like so: // Example Number String below. var numString = "10"; var transNum = ""; for(x=0;x<numString.length;x++) { var numChar = numString.charAt(x); transNum += numtxts[parseInt(numChar)]; } return transNum; The problem with this bit of code is that it groups the numbers, not sure if all languages do that, like the english language does...? Perhaps there's a better approach for this? Can anyone help please? Thanks :)

    Read the article

  • How to open a file and remove the last line?

    - by sologhost
    I am looking to open up a file, grab the last line in the file where the line = "?", which is the closing tag for a php document. Than I am wanting to append data into it and add back in the "?" to the very last line. I've been trying a few approaches, but I'm not having any luck. Here's what I got so far, as I am reading from a zip file. Though I know this is all wrong, just needing some help with this please... // Open for reading is all we can do with zips and is all we need. if (zip_entry_open($zipOpen, $zipFile, "r")) { $fstream = zip_entry_read($zipFile, zip_entry_filesize($zipFile)); $fp = fopen($curr_lang_file, 'r+b'); while (!feof($fp)) { $output = fgets($fp, 16384); if (trim($output) == '?>') break; fwrite($fp, $output); } fclose($fp); file_put_contents($curr_lang_file, $fstream, FILE_APPEND); } $curr_lang_file is a filepath string to the actual file that needs to have the fstream appended to it, but after we remove the last line that equals '?'

    Read the article

  • nextSibling issue, should be simple

    - by SoLoGHoST
    Ok, I'm trying to come to grips with this nextSibling function in JS. Here's my issue within the following code... var fromRow = document.getElementById("row_1"); while(fromRow.nodeType == 1 && fromRow.nextSibling != null) { var fRowId = fromRow.id; if (!fRowId) continue; // THIS ONLY gets done once and alerts "row_1" ONLY :( alert(fRowId); fromRow = fromRow.nextSibling; } Ok can someone please tell me what is wrong with this code? There are siblings next to this document.getElementById("row_1"); element for sure as I can see them, and they all have id attributes, so why is it not getting the id attributes of the siblings?? I don't get it. row_1 is a TR element, and I need to get the TR elements next to it within this table, but for some reason, it only gets the 1 element that I can already get using document.getElementById, arggg. Thanks guys :)

    Read the article

  • PHP preg_match, need some help

    - by SoLoGHoST
    Can someone please help me with this preg_match if (preg_match('~[^A-Za-z0-9_\./\]~', $filepath)) // Show Error message. I need to match a possible filepath. So I need to check for double slashes, etc. Valid file path strings should look like this only: mydir/aFile.php or mydir/another_dir/anyfile.js So a slash at the beginning of this string should be checked also. Please help. Thanks :)

    Read the article

< Previous Page | 1 2