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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 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. : )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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