Jump to content

trink

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by trink

  1. This is SUPPOSED to get the location of the Xth occurance of a character in a string, where $xpos is the occurance that you want to get, and $xchar is the character that you want to get. function strxpos($xtext,$xchar,$xpos){ $pshchar=strpos($xtext,$xchar); $owut=0; for($numon=1;$numon <= $xpos;$numon++){ $result=strpos($xtext,$xchar,$owut); $owut=(strpos($xtext,$xchar,$owut) + 1); } return $result; } It works to an extent. Say that there are only 5 occurances in the string, but the number for $xpos is 7. It will still retrieve a number, which I don't want it to do, for some reason its really wierd, i've tried replacing it with function strxpos($xtext,$xchar,$xpos){ //strxpos('a.b.c.d.e','.',3) returns 5 (first char in string is 0) $nrchars=substr_count($xtext,$xchar); $pshchar=strpos($xtext,$xchar); $owut=0; for($numon=1;$numon <= $xpos || $numon <= $nrchars;$numon++){ $result=strpos($xtext,$xchar,$owut); $owut=(strpos($xtext,$xchar,$owut) + 1); } return $result; } but still it bears no fruit, it just doesn't work at all when I change it to that. Any tips would be greatly appreciated. Thanks, Trink
  2. Sir, I like the way you think, we should collaborate some time. =P
  3. Say a user has their cursor in a text box and they click a button and want to add some information in, how would I get the current position of the cursor in the textbox to add that information in to that specific place? Any help would be greatly appreciated.
  4. In a function, how would I make a specific argument optional? Say I had something like this: function myfunction($a,$b,$c,$d){ if(!$d){ $d=1; } return $a.$b.$c.$d; } Thats basically what I'm trying to do with my function, and its not working. It returns the correct value, but I have to supress the error that it returns about not having a 4th argument with a @. So it ends up looking like @myfunction(1,2,3). I don't mind using the @ but I'd like to make the fourth argument optional. I'd appreciate any help on this topic.
  5. I know that strpos gets the position of the first occurance of N character in a string and that strrpos gets the position of the last occurance of N character in a string. But say I have a string that has 5 :'s in it. a:b:d:c:e:f How would i get the position of the Xth occurance, say, the 3rd. I've been looking all around and havent really found anything, maybe I havent researched it extensively enough, I'm not to sure if there is a specific command to do that or not, but any help with this would be greatly appreciated.
  6. Alright, what I've got is this: <?php $postx=$_POST[postx]; $msg=$_POST[msg]; $name=$_POST[name]; $isimg=''; $filename='posts.txt'; if($postx){ if(trim($name)){ if(trim($msg)){ if($_FILES['imgup'] ['tmp_name']){ move_uploaded_file($_FILES['imgup'] ['tmp_name'], "../img/{$_FILES['imgup'] ['name']}"); $isimg='<img class="leftfloat" src="'.$_FILES['imgup'] ['name'].'" />'; } fwrite($fp=fopen($filename, "a"), '<div class="ptitle"><center><b>'.$name.'</b></center></div><div class="post">'.$isimg.$msg.'</div><br>') && fclose($fp); }else{ if($_FILES['imgup'] ['tmp_name']){ move_uploaded_file($_FILES['imgup'] ['tmp_name'], "../img/{$_FILES['imgup'] ['name']}"); $isimg='<img class="leftfloat" src="'.$_FILES['imgup'] ['name'].'" />'; fwrite($fp=fopen($filename, "a"), '<div class="ptitle"><center><b>'.$name.'</b></center></div><div class="post">'.$isimg.$msg.'</div><br>') && fclose($fp); }else{ $message='You must have a message or a file in order to post.'; } }if(!trim($name)){ $message='You must use a name in order to post.'; } } $handle=fopen("posts.txt", "r"); $posts=fread($handle, filesize("posts.txt")); fclose($handle); ?> Basically what it's supposed to do is: If they click the submit button, its supposed to check if they have a name, if they don't, it sets $message as 'you must have a name blah blah'. If they have a name, then it checks if they have a message, if they do have a message then it checks if they have a file, and if they do, it uploads it and sets a variable as a link to it, then writes all the stuff to an external file. If they do not have a message, but they do have an image, then it uploads the image and writes it all to the file. If they do not have a message or an image, then it sets $message as 'you must have a message blah blah'. The problem is, when I open the page, it says that there was an "unexpected $end" found on the last line of the file. OR if I change that }if(!trim($name)){ line to }else{ it says that there is an "unexpected else" on that line. I've looked over this file at least 20 times and found nothing that could be causing the problem, any help would be appreciated. You can find the full document at http://71.97.138.27:1009/doesntwork.txt If the IP changes for some reason, I'll post the change. Any help would be greatly appreciated.
  7. And I've also found that if the file has & in it it won't write to filename.txt correctly. Such as 1 & 2.txt will only be written as 1.
  8. Alright, that all works perfectly, but there's only one problem. Say the file's name is you're.txt, well, it sets the url as index.php?data=you and ends where the ' was. I tried using <a href='index.php?data=str_replace(\"'\", \"%27\", $file)' and I was correct in assuming it wouldn't work. How would I avoid this problem and allow it to set the url as index.php?data=you're.txt?
  9. I tried that... I can see how it would work... it didn't for me. The php looks like this: $File = "filename.txt"; $Handle = fopen($File, 'w'); $Data = $_GET['file']; fwrite($Handle, $Data); fclose($Handle); There are 2 problems. #1: When I clicked a file, it showed the url as index.php?file=filename.here just fine, but it didnt write filename.here to filename.txt. #2: I don't want the file to be written UNTIL the file is clicked. I don't want filename.txt written when the page loads, because I have another application checking for that file, and if it is a file then it reads the contents of that file, does what it needs to do, then deletes filename.txt. So with this, it creates the file when the page is loaded, and has no idea what to do with it because filename.txt has no contents at that point.
  10. Basically, I'm very new to php. Like, just started working with it 5 days ago new. I've got a php script that gets the contents of a directory and posts them all as links, and the links look like this: <a href="javascript:document.all.fileclicked.value='$file';dophp()">$file</a> fileclicked is the name of a hidden input on the page. Basically when they click the link it sets the value of the hidden input as $file. Then it calls the dophp() function. The dophp function, in short, runs php code. Within that function I'm trying to get the value of the fileclicked hidden input and set it as a variable. Is it something like $Data = $_Get["fileclicked"]; or something? That's what I'd like to know. (I've tried $_Get and it didnt work, but I'm assuming it could be something close to that) I know that this probably isn't the best way of going about what I'd like to do either, and any tips on cleaning it up would be appreciated. Any help would be appreciated.
×
×
  • 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.