Jump to content

Php variable need help


miniop

Recommended Posts

Hello all,

 

Can someone help me ?

 

I have a html/php with a contact form and anyone can write his name and press submit.

Then his name is saved into a text.

 

1) Is it possible if someone write the url site like this www.mydomain.com/index.html?test={!variable} and complete the form name then in the plain text to be saved like this : {!varuable} , name.

 

2) And if someone try again to connect at the www.mydomain.com/index.html?test={!variable} and the variable is already in the text file then to redirect them to another page ?

 

Thank you very much.

Link to comment
https://forums.phpfreaks.com/topic/218203-php-variable-need-help/
Share on other sites

>>Do you know how to use mysql?

 

Yes and no but this is just for testing and i might change later to sql. ofcourse with sql will be easier.

 

I succeed take a ?test=<variable> with php.

 

Now anyone can help me how to pass this variable to another php ?

 

Example :

 

www.domain.com/1.php?name=123

on 1.php i have this code :

 

<?php

$num = $_GET['name']; 

?>

 

how i can pass the $num to another php like 2.php ? (2.php has the code so it can save the form to a text file ?)

 

Thank you.

>>Now anyone can help me how to pass this variable to another php ?

 

Found that also.

 

 

---

 

Now how i can serach a text file for a specific word and echo the result ? And also when the word is already 3 times in the text file then echo something else ?

 

Like :

 

i.txt contact the word "rock"

php serach the i.txt for the specific word "rock"

then echo your results is 1 time

 

We add 2 time the word "rock" in the i.txt

php seatch the i.txt for the specific word "rock" and it finds that there 3 time the word then echo END

 

Thank you.

  • 3 weeks later...

<?php

//open file
        $file_handle = fopen("myfile.txt", "rb");

//explode file to array, split by space
while (!feof($file_handle) ) {
    $words = explode(" ", $file_handle);
}

//set variables
//catchWord
$catchWord = 'myWord';

//catchLimit
$catchLimit = 3;

//loop over array and check against catchWord
foreach($words as $word){
	$i = 0;
                while($word == $catchWord){
		if($i <= $catchLimit){
			$i++;
			if($i > 1){$time = 'times';}else{$time = 'time';}
			echo 'The word '.$catchWord.' occurred '.$i.' '.$time.'.<br>';
		}
                        else{
                            break;
                        }
	}
}

?>

 

That's a basic example of one way you can achieve the desired result. It would need a slight modification to work exactly the way you want, but this is the theory.

 

I only tested it with a sample string. If there's an error during the file read portion I didn't really check that part, I'm sure you'll get it.

 

Good luck. : )

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.