Jump to content

sKunKbad

Members
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by sKunKbad

  1. I was working on the same thing last week. Check out this post, it may help you: http://www.phpfreaks.com/forums/index.php/topic,161946.msg708774.html#msg708774
  2. Nice code sasa! It's amazing the way that different people will try to solve the same problem. Check this out sparkbark: <?php session_start(); include('sasa_array.inc'); if (!array_key_exists('rand_text_files', $_SESSION)) $_SESSION['rand_text_files'] = $a_text_files; if (count($_SESSION['rand_text_files']) == 0) $_SESSION['rand_text_files'] = $a_text_files; shuffle($_SESSION['rand_text_files']); $rand_text = $_SESSION['rand_text_files'][0]; unset($_SESSION['rand_text_files'][0]); $handle = file($rand_text); foreach ($handle as $line_num => $line) { echo $line; } ?> The array of files in sasa_array.inc: <?php $a_text_files = array( 'file_a.txt', 'file_b.txt' , 'file_c.txt', 'file_d.txt', 'file_e.txt' ); ?>
  3. Maybe somebody can point out what is wrong with my script. It may be easier to fix it at this point, but I'm at work and can't spend time on it right now.
  4. Is your question, "what file permission value is necessary for my script to write to log.txt"?
  5. Make a "file not found" 404 error page with a redirect in it's header, or use .htaccess to redirect when "file not found".
  6. You are going to have to learn php for an explaination, but here is some code that will do what you want with files: <?php session_start(); function randomNoRepeat(){ include ('randomTextFiles.inc'); $max = count($arr); $num = Rand (0,($max-1)); if(isset($_SESSION['randomNums']) && in_array($num,$_SESSION['randomNums'])){ if (count($_SESSION['randomNums']) == $max){ $fileNum = $arr[$num]; $handle = file($fileNum); foreach ($handle as $line_num => $line) { echo $line; } unset($_SESSION['randomNums']); }else{ randomNoRepeat(); } }else{ $fileNum = $arr[$num]; $handle = file($fileNum); foreach ($handle as $line_num => $line) { echo $line; } $_SESSION[randomNums][] = $num; } } randomNoRepeat(); ?> And here is the include file with the names of the files you want to output. You didn't say what kind of files these are, so they may require some formatting to output the way you want. <?php $arr = array( 'file_a.txt', 'file_b.txt', 'file_c.txt', 'file_d.txt', 'file_e.txt' ); ?>
  7. sKunKbad

    WYSIWYG

    TinyMCE works on all the browsers I have tested. Win XP Safari Beta, IE6, IE7, Firefox and Opera.
  8. Here is another way you can do it, which is more convenient, because you can store all the text to be randomized in an array: <?php session_start(); function randomNoRepeat(){ include ('randomText.inc'); $max = count($arr); $num = Rand (0,($max-1)); if(isset($_SESSION['randomNums']) && in_array($num,$_SESSION['randomNums'])){ if (count($_SESSION['randomNums']) == $max){ echo $arr[$num]; unset($_SESSION['randomNums']); }else{ randomNoRepeat(); } }else{ echo $arr[$num]; $_SESSION[randomNums][] = $num; } } randomNoRepeat(); ?> Here is the include file I used that has the array in it: <?php $arr = array( 'I like tacos.', 'Becky loves to work at my store.', 'My brother is finally moving out!', 'I gotta get back to work.', 'Old ladies always have problems.' ); ?>
  9. You need to URL encode the string. See urlencode() in the php manual.
  10. There is no possible infinite loop with my code, run it and see.
  11. I was bored, so I made this, and it does work, but can probably be refined or changed to suit your needs: <?php session_start(); echo count($_SESSION['randomNums']) . "<br>"; print_r($_SESSION['randomNums']); function randomNoRepeat(){ $max= 6; $num = Rand (1,$max); if(isset($_SESSION['randomNums']) && in_array($num,$_SESSION['randomNums'])){ if (count($_SESSION['randomNums']) == 6){ switch ($num) { case 1: echo "Time is money"; break; case 2: echo "An apple a day keeps the doctor away"; break; case 3: echo "Elmo loves dorthy"; break; case 4: echo "Off to see the wizard"; break; case 5: echo "Tomorrow is another day"; break; case 6: echo "PHP is cool!"; } unset($_SESSION['randomNums']); }else{ randomNoRepeat(); } }else{ switch ($num) { case 1: echo "Time is money"; $_SESSION[randomNums][] = $num; break; case 2: echo "An apple a day keeps the doctor away"; $_SESSION[randomNums][] = $num; break; case 3: echo "Elmo loves dorthy"; $_SESSION[randomNums][] = $num; break; case 4: echo "Off to see the wizard"; $_SESSION[randomNums][] = $num; break; case 5: echo "Tomorrow is another day"; $_SESSION[randomNums][] = $num; break; case 6: echo "PHP is cool!"; $_SESSION[randomNums][] = $num; } } } randomNoRepeat(); ?>
  12. I found this: http://www.savdesign.com/articles.php?article_id=23 which is a javascript random image generator with no repeat. It can probably be easily adapted to text.
  13. You would have to take your standard text randomizer, and use something like cookies or a session to hold the values of the text that has already been output. I believe this would only work if the page refreshed each time, because I do not know if cookies/sessions can be used with ajax. I had a nice javascript text randomizer on my site, and I always wanted this functionality you desire, but never got around to implementing it. Please post your final code when you figure it out.
  14. Or just add a small Javascript to insert the current year each time. or php Copyright © <?php echo (date("Y")); ?>
  15. how about $lang = 'english'; if (!isset($_COOKIE)){ $lang = $_REQUEST['lang']; setcookie("TestCookie", $lang, time()+3600, "/", ".example.com", 1); }
  16. It looks like you are setting your cookie to expire right when you make it. time() is right now. You might try something like time() + 10000. This may not be the only thing wrong with your script.
  17. Try: <?php if (isset($_GET['stylesheet']){ $stylesheet = $_GET['stylesheet']; setcookie ("stylesheet", "$stylesheet", time()+9000, "/", "duelindeals.com", 0); header("Location: $HTTP_REFERER"); }else{ header("Location:http://www.duelindeals.com"); } ?>
  18. search for "magic quotes", and I'm sure you will find what you are looking for.
  19. if (preg_match('/^[a-z ]+$/i', $string)) { } else { } and $pattern = '/[^a-z ]/i'; preg_replace($pattern, "", $string); test those and see how they work for you
  20. I will check this out, but I found a couple of awesome scripts that will work perfectly for me. Actually, I already got both of them working last night. One is called FCKeditor, but it doesn't work on Win Safari when I tried it, so I'm not sure if it will work on other Safari browsers. The other is called TinyMCE, and it does work with Safari, but it is a bit clunky. Thanks for your post emehrkay. I will try to make this work too, since I want to know what is best for me and my customers.
  21. I'm making a database-less CMS and would like buttons in the text editor to apply bold, italic, underline, and make hyperlinks. The functionality would be similar to buttons when posting here on phpfreaks, however, the tags will be html, not bbcode. Does anyone know of a tutorial of applying tags to selected text using javascript? Thank you for any help or links.
  22. Just increase the number of seconds for your timeout to something bigger, like: curl_setopt($conn[$i], CURLOPT_TIMEOUT, 115);
  23. Well, I've got this script that is working as I wanted it to work, but I'm pretty sure this isn't the most efficient way of doing this. Any help is still appreciated. I can't be the only person who has ever wanted to do something like this. Isn't this like the basics of a CMS or something? <html> <head> <style type="text/css"> #editbox { width:500px; height:200px; } </style> </head> <body> <?php if ($_GET['editbox'] != ""){ //if the editbox has anything in it $filename = 'html_parse_4_links.txt'; //this is the file to write to $edit = $_GET['editbox']; //this is the contents of the editbox $before = $_GET['before']; $after = $_GET['after']; $somecontent = urldecode($before); $somecontent.= "<div id='somediv'>"; $somecontent.= $edit; $somecontent.= "</div>"; $somecontent.= urldecode($after); // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In the example, they were opening $filename in append mode "a", but here we are overwriting the file in mode "w". //"a" mode might be pretty cool for a appending a blog with a user comment... if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } }else{ $url = "html_parse_4_links.txt"; $input = @file_get_contents($url) or die('Could not access file: $url'); $regexp = "(.*)<div id='somediv'>(.*)<\/div>(.*)"; if(preg_match_all("/$regexp/si", $input, $matches)) { $beforeEdit = urlencode($matches[1][0]); $string = $matches[2][0]; $theEdit = htmlentities($string); $afterEdit = urlencode($matches[3][0]); echo "<form action='html_parse_4_links.php' method='get'> <input type='text' name='editbox' id='editbox' value='$theEdit'></input> <input type='hidden' name='before' value='$beforeEdit'></input> <input type='hidden' name='after' value='$afterEdit'></input> <input type='submit' value='Save Back 2 File' /> </form>"; } } ?> </body> </html> and here is the text file I was working with (named html_parse_4_links.txt) what the heck <div id='somediv'>im ready for a pepsi</div> blah blah blah
  24. I have been able to read in the text by parsing the html, but I still have not figured out how to write it back to the file. Here is the script to read it in: <?php $url = "file.txt"; $input = @file_get_contents($url) or die('Could not access file: $url'); $regexp = "<div id='somediv'>(.*)<\/div>"; if(preg_match_all("/$regexp/siU", $input, $matches)) { $string = $matches[1][0]; echo nl2br(htmlentities($string)); } ?> If anyone can help with the last half of this project, I'd appreciate it. I just need to know how to write back to the specific div (id="somediv"). Thanks for any help in advance.
  25. I came up with this script the other night while working on another person's question here in this forum: <html> <head> <style type="text/css"> #editbox { width:500px; height:200px; } </style> </head> <body> <?php if ($_GET['editbox'] != ""){ $filename = 'fread_text.txt'; $somecontent = $_GET['editbox']; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } }else{ $filename = "fread_text.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); echo "<form action='fread.php' method='get'> <input type='text' name='editbox' id='editbox' value='$contents'></input> <input type='submit' value='Submit' /> </form>"; fclose($handle); } ?> </body> </html> The script reads a file into a form's text area, allows a person to change that files text, and then writes the changed text back to the file when the submit button is pressed. My question is, how could I change only a selected div or paragraph of the file? For instance, if I wanted to only have the form read and change a paragraph whose ID is "paragraph1", how could I do that?
×
×
  • 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.