Jump to content

AquariaXI

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by AquariaXI

  1. Someone can help? This person obviously doesn't want to really help me...
  2. This makes absolutely no sense to me. I learn by example. I simply want to use // Find all <td> whose attribute id="BLAH" $doc = new DOMDocument ( ); $doc -> loadHTMLFile ( 'index.php' ); $child = $doc -> getElementsByTagName ( 'td' ); foreach ( $child as $td ) { if ( $td -> hasAttribute ( 'id' ) ) { echo $td -> attributes -> getNamedItem ( 'id' ) -> nodeValue . '<br>\r\n'; } } Now, this returns "colors" which is the id. not the value OF colors. It also comes with a warning It at least SEEMS to me at the moment at least, that you are simply trying to avoid the answer.
  3. As the title says, how can i check if multiple arrays exist inside an array or not? Any help is greatly appreciated!
  4. I didn't ask you to do it for me. I simply asked for how I can grab getElementFromId data in PHP from jquery using DomDocument...
  5. Isn't there a way to use <?php // Create a new DOM Document $dom = new DOMDocument('1.0', 'iso-8859-1'); // Enable validate on parse $dom->validateOnParse = true; // Create a div element $element = $dom->appendChild(new DOMElement('div', 'Hey, this is the text content of the div element.')); // Create a id attribute to div $attr = $element->setAttributeNode( new DOMAttr('id', 'my_id')); // Set that attribute as id $element->setIDAttribute('id', true); // Get the tag content $tagcontent = $dom->getElementById('my_id')->textContent; echo $tagcontent; ?> ? except i don't want a div, i want the td's "shades" & "tints"
  6. I don't want to have to submit it. The "Update" button does not "submit", it just instantly changes the hex values.
  7. Correct. I just want to echo out the chosen hex values from within the "shades" td & "tints" td id tags When the user interacts with the "Update" button, when they hit it, it changes the tints / shades hex values that are held within the "shades" id & "tints" id td tags.
  8. ding ding ding! CORRECT! The user DOES interact with the page to change what values are being shown in the table. anyway, this is the table : <table class="color_frame"> <tr> <td class="picker_box"> <div class="color_wrapper"> <div id="colorpickerHolder"></div> <div class="top_bar"> <div class="color_panel"> <!--Color Panel--> </div> </div> <input type="button" value="&nbsp;" class="update_btn" /> </div> </td> <td class="color_map"><img src="images/color_map.gif" alt="Shade and Tint map" /></td> <td id="colors" class="shade_box"> <table id="shades"></table> <table id="tints"></table> </td> </tr> </table>
  9. function hex2rgb ( hex ) { hex = hex.replace ( '#', '' ); r = parseInt ( hex.substring ( 0, 2 ), 16 ); g = parseInt ( hex.substring ( 2, 4 ), 16 ); b = parseInt ( hex.substring ( 4, 6 ), 16 ); result = 'rgb(' + ( r + ', ' + g + ', ' + b + ')' ); return result; } function rgb2hex ( rgb ) { rgb = rgb.match ( /^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i ); return ( rgb && rgb.length === 4 ) ? "#" + ( "0" + parseInt ( rgb [ 1 ], 10 ).toString ( 16 ) ).slice ( -2 ) + ( "0" + parseInt ( rgb [ 2 ], 10 ).toString ( 16 ) ).slice ( -2 ) + ( "0" + parseInt ( rgb [ 3 ], 10 ).toString ( 16 ) ).slice ( -2 ) : "" } for ( var i = 0; i < 10; i++ ) { var shadeHex = rgb2hex ( String ( 'rgb(' + shades [ 9 - i ].rgb + ')' ) ); var tintHex = rgb2hex ( String ( 'rgb(' + tints [ i ].rgb + ')' ) ); $ ( "#shades" ).append ( '<tr>' + '<td class="hexcolor">' + '<a style="background : ' + shadeHex + '"></a>' + '</td>' + '<td class="hexcode">' + shadeHex + '</td>' + '</tr>' ); $ ( "#tints" ).append ( '<tr>' + '<td class="hexcolor">' + '<a style="background : ' + tintHex + '"></a>' + '</td>' + '<td class="hexcode">' + tintHex + '</td>' + '</tr>' ); } this is my whole jquery code
  10. i dont understand... T_T I said the jquery is serving up the tds : $ ( "#shades" ).append ( '<tr>' + '<td class="hexcolor">' + '<a style="background : ' + shadeHex + '"></a>' + '</td>' + '<td class="hexcode">' + shadeHex + '</td>' + '</tr>' );
  11. How would YOU do it then? I've been trying to figure out how to grab the `td` `shades` data from php for 18 hours now.
  12. Yes & ONLY grab the value{s} between "<td id=\"shades\">DATA HERE</td>" - It is to grab the color hexes from my jquery hex array & echo them out in php. and NO I cannot build the table in PHP. the hex values are generated from jquery ONLY & are put inside the table with the id, "shades"
  13. Made a typo HTML [ 0 ] = $string; should be $HTML [ 0 ] = $string;
  14. So I'm trying to grab values from a specific table id in html in PHP possibly using `DOMElement` or something else? I want to add my index.php page to a variable, search for a certain table id ( in this case, "shades" ), then grab JUST the values from inside that table & print it out in an echo. Here's what i have. for some reason I'm getting Warning: DOMDocument::loadHTML(): htmlParseEntityRef: no name in Entity <?php $HTML = [ ]; $stream = fopen ( "index.php", "r" ); $string = stream_get_contents ( $stream ); HTML [ 0 ] = $string; // Our HTML goes here $innerHTML = implode ( ',', $HTML ); // Create a new DOMDocument based on our HTML $document = new DOMDocument; $document -> loadHTML ( $innerHTML ); // Get a NodeList of any table "id", "shades" $cells = $document -> getElementsByTagName ( "id" ); // Cycle over each <td>, adding its HTML to $innerHTML foreach ( $cells as $cell ) { $innerHTML = $document -> saveHTML ( $cell ); } // Output our glorious HTML echo $innerHTML; fclose ( $stream ); ?> Any help is absolutely appreciated!
  15. So I'm trying to create an Array from a comma separated string containing array{s}. How can I take a string full of comma separated hex values such as : <?php $myStr = ( "00ffff", "00cccc", "009999", "007777", "004444", "001111", "01ffff", "01cccc", "019999" ); ?> & turn it into 3 separated arrays like : <?php $myNewArrs = [ Array1 ( 3 ), Array2 ( 3 ), Array3 ( 3 ), ]; ?> which REALLY looks like : <?php $myNewArrs = [ Array ( "00ffff", "00cccc", "009999" ), Array ( "007777", "004444", "001111" ), Array ( "01ffff", "01cccc", "019999" ), ]; ?> ? Any assistance is most-definitely appreciated! Thank you & have a great afternoon!
  16. Here's what that wrote to the file : ff00ff, ff00cc, ff0099, ff0066, ff0033, ff0000, ff3300, ff6600, ff9900, ffcc00, ffff00, ccff00, 99ff00, 66ff00, 33ff00, 00ff00, 00ff33, 00ff66, 00ff99, 00ffcc, 00ffff, 00ccff, 0099ff, 0066ff, 0033ff, 0000ff, 3300ff, 6600ff, 9900ff, cc00ff, 9900ff, 6600ff, 3300ff, 0000ff, 0033ff, 0066ff, 0099ff, 00ccff, 00ffff, 00ffcc, 00ff99, 00ff66, 00ff33, 00ff00, 33ff00, 66ff00, 99ff00, ccff00, ffff00, ffcc00, ff9900, ff6600, ff3300, ff0000, ff0033, ff0066, ff0099, ff00cc, ff00ff It is all one line. It needs to look exactly like the hex I wrote in the code above.
  17. Correct. And yes I've already tried strings, but it's unfortunately only creating 1 long string & plus I need the ability to create as many hex color codes as needed to write to the file.
  18. Basically, "ff00ff", "ff00cc", "ff0099", "ff0066", "ff0033", "ff0000", "ff3300", "ff6600", "ff9900", "ffcc00", "ffff00", "ccff00", "99ff00", "66ff00", "33ff00", "00ff00", "00ff33", "00ff66", "00ff99", "00ffcc", "00ffff", "00ccff", "0099ff", "0066ff", "0033ff", "0000ff", "3300ff", "6600ff", "9900ff", "cc00ff", "9900ff", "6600ff", "3300ff", "0000ff", "0033ff", "0066ff", "0099ff", "00ccff", "00ffff", "00ffcc", "00ff99", "00ff66", "00ff33", "00ff00", "33ff00", "66ff00", "99ff00", "ccff00", "ffff00", "ffcc00", "ff9900", "ff6600", "ff3300", "ff0000", "ff0033", "ff0066", "ff0099", "ff00cc", "ff00ff" is what I want to see in the file ( YES, including the double quotes ) & YES, in the format seen above. After every 3rd comma, starts a new line.
  19. @requinix Now I think I understand you. If I don't, I apologize in advance. SO.... 1st, here's all the functions used to write to this file ( which is a CSV in this case ) includes/file-mainframe.php : <?php function implodeAll ( $glue, $arr ) { for ( $i = 0; $i < count ( $arr ); $i++ ) { if ( @is_array ( $arr [ $i ] ) ) { $arr [ $i ] = CSV :: implodeAll ( $glue, $arr [ $i ] ); } } } function SplitFileByDelimiter ( $content, $delimiter = ",", $delimCount = 3 ) { $content = [ $content ]; $content = implode ( $delimiter, $content ); return $content; } function checkDelimiter ( $content, $throwExceptionOnNonUnique = true, $expectSingleColumn = false ) { // Would be cleaner if you pass the delimiters from outside // as also the order matters in the special case you've got something like "a,b;c" // & you don't throw the exception - then the first match is prefered // But for StackOverflow I put them inside $delimiters = [ "\t", ";", "|", "," ]; $result = ','; $maxCount = 0; foreach ( $delimiters as $delimiter ) { // Impress your code reviewer by some good regex $pattern = "/(?<!\\\)(?:\\\\\\\)*(?!\B\"[^\\\"]*)\\" . $delimiter . "(?![^\"]*\\\"\B)/"; $amount = preg_match_all ( $pattern, $content ); if ( $maxCount > 0 && $amount > 0 && $throwExceptionOnNonUnique ) { $msg = 'Identifier is not clear : "' . $result . '" & "' . $delimiter . '" are possible'; throw new Exception ( $msg ); } if ( $amount > $maxCount ) { $maxCount = $amount; $result = $delimiter; } } // If nothing matches & you don't expect that just the CSV just // consists of one single column without a delimeter at the end if ( $maxCount === 0 && ! $expectSingleColumn ) { throw new Exception ( 'Unknown delimiter' ); } return $result; } function WriteFile ( $filename, ...$content ) { if ( gettype ( $content ) === 'array' ) { $content = File :: implodeAll ( ', ', $content ); } $list = [ $content ]; $delimiters = File :: checkDelimiter ( $content, true, false ); $fp = fopen ( $filename, 'w' ); foreach ( $list as $fields ) { $fields = File :: SplitFileByDelimiter ( $fields, ",", 3 ); file_put_contents ( $filename, $fields ); } fclose ( $fp ); } function ReadCSV ( $filename ) { // Read a CSV file $handle = fopen ( $filename, "r" ); // Optionally, you can keep the number of the // line of the loop it's currently // iterating over $lineNumber = 1; // Add new Data Array to dump all data $myData = [ ]; // Iterate over every line of the file while ( ( $raw_string = fgets ( $handle ) ) !== false ) { // Parse the raw csv string: "1, a, b, c" $row = str_getcsv ( $raw_string ); $myData = [ $row ]; // into an array: ['1', 'a', 'b', 'c'] // And do what you need to do with every line var_dump ( $myData [ 0 ] ); // Increase the current line $lineNumber++; } fclose ( $handle ); return $myData [ 0 ]; } ?> <?php include_once ( 'includes/file-mainframe.php' ); $file -> WriteFile ( $filepath . $filename, [ "ff00ff", "ff00cc", "ff0099", "ff0066", "ff0033", "ff0000", "ff3300", "ff6600", "ff9900", "ffcc00", "ffff00", "ccff00", "99ff00", "66ff00", "33ff00", "00ff00", "00ff33", "00ff66", "00ff99", "00ffcc", "00ffff", "00ccff", "0099ff", "0066ff", "0033ff", "0000ff", "3300ff", "6600ff", "9900ff", "cc00ff", "9900ff", "6600ff", "3300ff", "0000ff", "0033ff", "0066ff", "0099ff", "00ccff", "00ffff", "00ffcc", "00ff99", "00ff66", "00ff33", "00ff00", "33ff00", "66ff00", "99ff00", "ccff00", "ffff00", "ffcc00", "ff9900", "ff6600", "ff3300", "ff0000", "ff0033", "ff0066", "ff0099", "ff00cc", "ff00ff" ] ); $fileData = $file -> ReadCSV ( $filepath . $filename ); echo var_dump ( $fileData ); die ( ); ?> So when I use this in var_dump ( ), I get array(59) { [0]=> string(6) "ff00ff" [1]=> string(7) " ff00cc" [2]=> string(7) " ff0099" [3]=> string(7) " ff0066" [4]=> string(7) " ff0033" [5]=> string(7) " ff0000" [6]=> string(7) " ff3300" [7]=> string(7) " ff6600" [8]=> string(7) " ff9900" [9]=> string(7) " ffcc00" [10]=> string(7) " ffff00" [11]=> string(7) " ccff00" [12]=> string(7) " 99ff00" [13]=> string(7) " 66ff00" [14]=> string(7) " 33ff00" [15]=> string(7) " 00ff00" [16]=> string(7) " 00ff33" [17]=> string(7) " 00ff66" [18]=> string(7) " 00ff99" [19]=> string(7) " 00ffcc" [20]=> string(7) " 00ffff" [21]=> string(7) " 00ccff" [22]=> string(7) " 0099ff" [23]=> string(7) " 0066ff" [24]=> string(7) " 0033ff" [25]=> string(7) " 0000ff" [26]=> string(7) " 3300ff" [27]=> string(7) " 6600ff" [28]=> string(7) " 9900ff" [29]=> string(7) " cc00ff" [30]=> string(7) " 9900ff" [31]=> string(7) " 6600ff" [32]=> string(7) " 3300ff" [33]=> string(7) " 0000ff" [34]=> string(7) " 0033ff" [35]=> string(7) " 0066ff" [36]=> string(7) " 0099ff" [37]=> string(7) " 00ccff" [38]=> string(7) " 00ffff" [39]=> string(7) " 00ffcc" [40]=> string(7) " 00ff99" [41]=> string(7) " 00ff66" [42]=> string(7) " 00ff33" [43]=> string(7) " 00ff00" [44]=> string(7) " 33ff00" [45]=> string(7) " 66ff00" [46]=> string(7) " 99ff00" [47]=> string(7) " ccff00" [48]=> string(7) " ffff00" [49]=> string(7) " ffcc00" [50]=> string(7) " ff9900" [51]=> string(7) " ff6600" [52]=> string(7) " ff3300" [53]=> string(7) " ff0000" [54]=> string(7) " ff0033" [55]=> string(7) " ff0066" [56]=> string(7) " ff0099" [57]=> string(7) " ff00cc" [58]=> string(7) " ff00ff" } array(59) { [0]=> string(6) "ff00ff" [1]=> string(7) " ff00cc" [2]=> string(7) " ff0099" [3]=> string(7) " ff0066" [4]=> string(7) " ff0033" [5]=> string(7) " ff0000" [6]=> string(7) " ff3300" [7]=> string(7) " ff6600" [8]=> string(7) " ff9900" [9]=> string(7) " ffcc00" [10]=> string(7) " ffff00" [11]=> string(7) " ccff00" [12]=> string(7) " 99ff00" [13]=> string(7) " 66ff00" [14]=> string(7) " 33ff00" [15]=> string(7) " 00ff00" [16]=> string(7) " 00ff33" [17]=> string(7) " 00ff66" [18]=> string(7) " 00ff99" [19]=> string(7) " 00ffcc" [20]=> string(7) " 00ffff" [21]=> string(7) " 00ccff" [22]=> string(7) " 0099ff" [23]=> string(7) " 0066ff" [24]=> string(7) " 0033ff" [25]=> string(7) " 0000ff" [26]=> string(7) " 3300ff" [27]=> string(7) " 6600ff" [28]=> string(7) " 9900ff" [29]=> string(7) " cc00ff" [30]=> string(7) " 9900ff" [31]=> string(7) " 6600ff" [32]=> string(7) " 3300ff" [33]=> string(7) " 0000ff" [34]=> string(7) " 0033ff" [35]=> string(7) " 0066ff" [36]=> string(7) " 0099ff" [37]=> string(7) " 00ccff" [38]=> string(7) " 00ffff" [39]=> string(7) " 00ffcc" [40]=> string(7) " 00ff99" [41]=> string(7) " 00ff66" [42]=> string(7) " 00ff33" [43]=> string(7) " 00ff00" [44]=> string(7) " 33ff00" [45]=> string(7) " 66ff00" [46]=> string(7) " 99ff00" [47]=> string(7) " ccff00" [48]=> string(7) " ffff00" [49]=> string(7) " ffcc00" [50]=> string(7) " ff9900" [51]=> string(7) " ff6600" [52]=> string(7) " ff3300" [53]=> string(7) " ff0000" [54]=> string(7) " ff0033" [55]=> string(7) " ff0066" [56]=> string(7) " ff0099" [57]=> string(7) " ff00cc" [58]=> string(7) " ff00ff" } OR array(59) { [0]=> string(6) "ff00ff" [1]=> string(7) " ff00cc" [2]=> string(7) " ff0099" [3]=> string(7) " ff0066" [4]=> string(7) " ff0033" [5]=> string(7) " ff0000" [6]=> string(7) " ff3300" [7]=> string(7) " ff6600" [8]=> string(7) " ff9900" [9]=> string(7) " ffcc00" [10]=> string(7) " ffff00" [11]=> string(7) " ccff00" [12]=> string(7) " 99ff00" [13]=> string(7) " 66ff00" [14]=> string(7) " 33ff00" [15]=> string(7) " 00ff00" [16]=> string(7) " 00ff33" [17]=> string(7) " 00ff66" [18]=> string(7) " 00ff99" [19]=> string(7) " 00ffcc" [20]=> string(7) " 00ffff" [21]=> string(7) " 00ccff" [22]=> string(7) " 0099ff" [23]=> string(7) " 0066ff" [24]=> string(7) " 0033ff" [25]=> string(7) " 0000ff" [26]=> string(7) " 3300ff" [27]=> string(7) " 6600ff" [28]=> string(7) " 9900ff" [29]=> string(7) " cc00ff" [30]=> string(7) " 9900ff" [31]=> string(7) " 6600ff" [32]=> string(7) " 3300ff" [33]=> string(7) " 0000ff" [34]=> string(7) " 0033ff" [35]=> string(7) " 0066ff" [36]=> string(7) " 0099ff" [37]=> string(7) " 00ccff" [38]=> string(7) " 00ffff" [39]=> string(7) " 00ffcc" [40]=> string(7) " 00ff99" [41]=> string(7) " 00ff66" [42]=> string(7) " 00ff33" [43]=> string(7) " 00ff00" [44]=> string(7) " 33ff00" [45]=> string(7) " 66ff00" [46]=> string(7) " 99ff00" [47]=> string(7) " ccff00" [48]=> string(7) " ffff00" [49]=> string(7) " ffcc00" [50]=> string(7) " ff9900" [51]=> string(7) " ff6600" [52]=> string(7) " ff3300" [53]=> string(7) " ff0000" [54]=> string(7) " ff0033" [55]=> string(7) " ff0066" [56]=> string(7) " ff0099" [57]=> string(7) " ff00cc" [58]=> string(7) " ff00ff" } array(59) { [0]=> string(6) "ff00ff" [1]=> string(7) " ff00cc" [2]=> string(7) " ff0099" [3]=> string(7) " ff0066" [4]=> string(7) " ff0033" [5]=> string(7) " ff0000" [6]=> string(7) " ff3300" [7]=> string(7) " ff6600" [8]=> string(7) " ff9900" [9]=> string(7) " ffcc00" [10]=> string(7) " ffff00" [11]=> string(7) " ccff00" [12]=> string(7) " 99ff00" [13]=> string(7) " 66ff00" [14]=> string(7) " 33ff00" [15]=> string(7) " 00ff00" [16]=> string(7) " 00ff33" [17]=> string(7) " 00ff66" [18]=> string(7) " 00ff99" [19]=> string(7) " 00ffcc" [20]=> string(7) " 00ffff" [21]=> string(7) " 00ccff" [22]=> string(7) " 0099ff" [23]=> string(7) " 0066ff" [24]=> string(7) " 0033ff" [25]=> string(7) " 0000ff" [26]=> string(7) " 3300ff" [27]=> string(7) " 6600ff" [28]=> string(7) " 9900ff" [29]=> string(7) " cc00ff" [30]=> string(7) " 9900ff" [31]=> string(7) " 6600ff" [32]=> string(7) " 3300ff" [33]=> string(7) " 0000ff" [34]=> string(7) " 0033ff" [35]=> string(7) " 0066ff" [36]=> string(7) " 0099ff" [37]=> string(7) " 00ccff" [38]=> string(7) " 00ffff" [39]=> string(7) " 00ffcc" [40]=> string(7) " 00ff99" [41]=> string(7) " 00ff66" [42]=> string(7) " 00ff33" [43]=> string(7) " 00ff00" [44]=> string(7) " 33ff00" [45]=> string(7) " 66ff00" [46]=> string(7) " 99ff00" [47]=> string(7) " ccff00" [48]=> string(7) " ffff00" [49]=> string(7) " ffcc00" [50]=> string(7) " ff9900" [51]=> string(7) " ff6600" [52]=> string(7) " ff3300" [53]=> string(7) " ff0000" [54]=> string(7) " ff0033" [55]=> string(7) " ff0066" [56]=> string(7) " ff0099" [57]=> string(7) " ff00cc" [58]=> string(7) " ff00ff" } I hope this helps!
  20. 1 ) yes, it is a variable. 2 ) In order to put a real value into it, I need to split it into 3 comma separated lines. I don't know how much more clear I can be. 3 ) As I said before, color hex.
  21. @requinix it's just gonna be a bunch of color hex codes. I can't really explain it more than that.
  22. @requinix Well yes, it IS supposed to be CSV, but unless I have to, I don't want to use fOpenCSV ( ) or w/e that function is. I just want to turn the raw arrays into a string then split them at their 3rd comma.
  23. @requinix function checkDelimiter ( $content, $throwExceptionOnNonUnique = true, $expectSingleColumn = false ) { // Would be cleaner if you pass the delimiters from outside // as also the order matters in the special case you've got something like "a,b;c" // & you don't throw the exception - then the first match is prefered // But for StackOverflow I put them inside $delimiters = [ "\t", ";", "|", "," ]; $result = ','; $maxCount = 0; foreach ( $delimiters as $delimiter ) { // Impress your code reviewer by some good regex $pattern = "/(?<!\\\)(?:\\\\\\\)*(?!\B\"[^\\\"]*)\\" . $delimiter . "(?![^\"]*\\\"\B)/"; $amount = preg_match_all ( $pattern, $content ); if ( $maxCount > 0 && $amount > 0 && $throwExceptionOnNonUnique ) { $msg = 'Identifier is not clear : "' . $result . '" & "' . $delimiter . '" are possible'; throw new Exception ( $msg ); } if ( $amount > $maxCount ) { $maxCount = $amount; $result = $delimiter; } } // If nothing matches & you don't expect that just the value consists of one single column without a delimeter at the end if ( $maxCount === 0 && ! $expectSingleColumn ) { throw new Exception ( 'Unknown delimiter' ); } return $result; } function SplitFileByDelimiter ( $content, $delimiter = ",", $delimCount = 3 ) { // Turn array into string $content = implode ( $delimiter, $content ); return $content; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.