Jump to content

Prismatic

Members
  • Posts

    503
  • Joined

  • Last visited

Everything posted by Prismatic

  1. To elaborate, You would create a timestamp at the start of your script, then one at the end. Subtract the start time from the end time and you have the total time taken for script execution.
  2. @ just suppresses errors generated by a function. The problem is still there
  3. simplexml_load_file() returns false when a file cannot be loaded, so you can simply remove the or xxx part and check $xml for false
  4. I know, I went back, clicked reply again and kept getting the message until I eventually gave up
  5. before I gave up trying to post a reply it had been 1.5 minutes and I was still getting the under 25 second message.
  6. Well actually web 2.0 has incorporated IRC into it, most chat rooms you hit online are backed in some form or another by an IRC server.
  7. Using a string shouldn't be much different then a file, once you've exploded it at the new line char you simply loop through the array much the same way you originally used fgets to read a single line in. It's getting there woo!
  8. wow bob, you don't know how much I appreciate the work Just ran it and it seems to be running things multiple times, I'll take a look and see if I can figure anything out
  9. Ok this is what it is now. Tell me if you see anything wrong with it, because all the function is doing is returning <explodeHere> <?php $code = "var = 'Test!'; { if(nest = true) { indent; } else { outdent; } }"; function findBlockQuotes($code, $firstStr = NULL){ //$firstStr holds the first string of each block. you'll see y. $block = array(); /** Break the line into an array and look for the first non-whitespace character */ $firstStrLen = str_split($firstStr); $sCount = (int)0; foreach($firstStrLen as $skey => $sVal) { if($sVal == " ") { $sCount++; } elseif($sVal == " ") { $sCount = $sCount + 4; } else { break; } } $prevIndent = $sCount; //change this line to whatever you need in order to get the length of $firstStr $lineArray = explode("\n", $code); //while($line = fgets($fh)){ foreach($lineArray as $key => $line) { /** Break the line into an array and look for the first non-whitespace character */ $indentCount = str_split($line); $iCount = (int)0; foreach($indentCount as $iKey => $iVal) { if($iVal == " ") { $iCount++; } elseif($iVal == " ") { $iCount = $iCount + 4; } elseif($iVal != " " || $iVal != " ") { break; } } $curIndent = $iCount; //get the length of the current indent; if(is_null($prevIndent)) { $prevIndent = $curIndent; //prevent going into infinite recursion. } else{ $block[] = $firstStr; //for every recursion but the first, add $firstStr to the block, because it belongs here } if($prevIndent < $curIndent) { //echo "prev < cur<br>"; $line = array_pop($block); //get last line, since it's indent level belongs to the parent block $blockStr = implode("\n", $block); //put it all in a string and return it. $returnStr = $blockStr."<explodeHere>".$line; //append $line onto $blockStr so it can be returned, but add an easy-to-find explode indicator return $returnStr; } else if($prevIndent > $curIndent ) { //echo "prev > cur<br>"; $tmp = explode("<explodeHere>", findBlockQuotes($code, $line)); //seperate the block from the next line of current indent level $block[] = '<blockquote>'.$tmp[0].'</blockquote>'; //put the nested stuff in a blockquote $block[] = $tmp[1]; //this is the extra line } else{ //echo "same<br>"; $block[] = trim($line); //get rid of indent, because you will nest blockquotes instead } } return implode("\n", $block); //when the file runs out of lines, return the stuff } //call the function $nestedBlocks = '<blockquote>'.findBlockQuotes($code).'<blockquote>'; echo $nestedBlocks; ?>
  10. Ok bob I noticed you never use $firstStr anywhere else except in the function head, where's it supposed to go?
  11. This is what I came up with <?php $code = " var = 'Test!'; { if(nest = true) { indent; } else { outdent; } }"; function findBlockQuotes($code, $firstStr = ""){ //$firstStr holds the first string of each block. you'll see y. $block = array(); $prevIndent = NULL; $lineArray = explode("\n", $code); //while($line = fgets($fh)){ foreach($lineArray as $key => $line) { $indentCount = str_split($line); $iCount = 0; foreach($indentCount as $iKey => $iVal) { if($iVal == " ") { $iCount++; } elseif($iVal == " ") { $iCount = $iCount + 4; } elseif($sVal != " " || $sVal != " ") { break; } } $curIndent = $iCount; //get the length of the current indent; if(is_null($prevIndent)) { $prevIndent = $curIndent; } //prevent going into infinite recursion. if($prevIndent < $curIndent) { $line = array_pop($block); //get last line, since it's indent level belongs to the parent block $blockStr = implode("\n", $block); //put it all in a string and return it. $returnStr = $blockStr."<explodeHere>".$line; //append $line onto $blockStr so it can be returned, but add an easy-to-find explode indicator return $returnStr; } else if($prevIndent > $curIndent ) { $tmp = explode("<explodeHere>", findBlockQuotes($code, $line)); //seperate the block from the next line of current indent level $block[] = '<blockquote>'.$tmp[0].'</blockquote>'; //put the nested stuff in a blockquote $block[] = $tmp[1]; //this is the extra line } else{ $block[] = trim($line); //get rid of indent, because you will nest blockquotes instead } } return implode("\n", $block); //when the file runs out of lines, return the stuff } //call the function $nestedBlocks = '<blockquote>'.findBlockQuotes($code).'<blockquote>'; echo $nestedBlocks; ?> Result <blockquote> var = 'Test!';<explodeHere>{<blockquote> At least it echoed something!
  12. Wayne, I cannot use HTML in the output, just basic BB code which includes [blockquote] [color=xxxx] [b] [i] [u] Bob, what's missing from here? "$curIndent = //get the length of the current indent; " Edit - ah ok I see
  13. Ok so quick rundown, I've created a script to make formatted code for a forum that doesn't have any code posting options. You put your code in and the script runs through each line of the code, splits each line into an array of characters then runs through each line until it hits a non-whitespace character, replacing each space or tab with the appopriate number of periods as it goes along. It's working wonderfully and the code looks great, however you cant copy and paste the code once it's been run through since it's now indented with periods. The idea is to use blockquotes now, which will allow me to indent the code but also preserve the ability for anyone to copy it off the forum without it being trashed with periods, but i'm just not sure how I would go about doing it. Below is a picture of what I mean. Each line represents a line of code, I would need the script to be able to find blocks of indented code and throw a blockquote around groups of indented code. If anyone has any ideas I'd appreciate it. Just looking for ideas here
  14. Here's what I want to do, search through posted code and find the 3 most common types of comments, /* */ // and # // and # are single line so I thought something like this would work /** match //text */ $code = preg_replace("/\/\/(.*?)(.*?)/", " [color=green][b]//\\1[/b][/color] ", $code); /** match #text */ $code = preg_replace("/\#(.*?)/", " [color=lightgreen][b]#\\1[/b][/color] ", $code); However it's only grabbing the # and // leaving everything to the right out And /* comments can run until they hit a */, which makes the multi line, I tried this but it also doesn't work $code = preg_replace("/\/\*(.*?)\/\*/s", " [color=green][b]/*\\1*/[/b][/color] ", $code); anyone know what I need to do to make these work?
  15. UPDATE table SET column = '$var' WHERE column = 'something'
  16. For one it helps if you plan on changing domains or do. If your script generates links in http://xxxx.com/script.php format and you change your domain to yyyy.com, you would have to update every single place the script links.
  17. <?php for ($i = 1; $i <= $j; $i++){ $_SESSION['iter'] = $i; echo '<img src="image.php"> '; } ?> <?php //image.php $i = $_SESSION['iter']; unset($_SESSION['iter']); //other stuff ?>
  18. How would I modify that to match nested functions as well? if(is_numeric(666)) for example? discomatt, your pattern didn't seem to match anything =/
  19. Unsolved this because I discovered an issue It's matching the entire string, for example function LoadGif($imgname) Only LoadGif($imgname) should be found and made bold, however it's also pulling in everything to the left of that too Any ideas on how to make it not go back like that?
  20. Doh. Figured it out lol $code = preg_replace("/(.*?)\((.*?)\)/", "[b]\\1([/b]\\2[b])[/b]", $code);
  21. I'm attempting to match any string that looks like this bleh(stuff) bleh and stuff can be anything.. this is the code I have, but it's obviously wrong since it doesn't work $code = preg_replace("/(.*?)((.*?))", "[b]\\1([/b]\\2[b])[/b]", $code); I'm building a code formatter and trying to match functions so I can make them bold. Any ideas?
×
×
  • 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.