-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
eh..nono don't think that will work. Think you will still get feedback. LoL wow that's a mind warp. I suppose what you're doing is okay.
-
no...well, yeah..you can see what happens when you do. Index.php already echoes out the information but when you add the parsing code calling itself, you get "feedback." If I'm understanding your setup right..just use the one file index.php. Whatever you do in it to echo out the actual content, instead of that, save all output to $content variable first, run the parse script on it, and THEN echo $content.
-
google php regex.
-
alright then. Since you're seeing data then it's not a php problem it's a javascript problem. moving thread.
-
so...okay so like, are you saying that you put that parsing code inside index.php and so when you run index.php it is doing file_get_contents("index.php") on itself, and it is giving you two copies of the content?
-
$result = mysql_query($sql); while($myrow = mysql_fetch_array($result)) { $itemId = $myrow['itemId']; $price = $myrow['price']; $quantity = $myrow['qty']; $date = $myrow['date']; $mailcontent.= "Item Id: ".$itemId."\n" ."Quantity: ".$quantity."\n" ."Date: " .$date."\n" ."Customer email: ".$email."\n" ."Shipping Address: \n" .$shipadd."\n"; } mail($to, $subject, $mailcontent,$additional_headers);
-
[SOLVED] function not working, need help please
.josh replied to jesushax's topic in PHP Coding Help
try adding $data = ... before all your str_replace(...); function paragraphs($data) { strip_tags($data, "<p>"); if(substr($data, 0,3) == '<p>' && substr($data, -4) == '</p>') { $data = substr($data, 3); $data = substr($data, 0, -4); } $data = str_replace("<br /><br />","</p><p>",$data); $data = str_replace("<br />","",$data); $data = str_replace("<p>","</p><p>",$data); $data = str_replace("</p><p></p><p>","</p><p>",$data); return($data); } -
I don't know how you got it setup but I got to ask: why not just use file_get_contents on page to begin with? I mean, can you explain why you need to store it in a different file before using file_get_contents()? Aren't you going to have to take the results and put it back into the original? In other words, it seems to me that you are doing this: source -> copy to include file -> parse include file -> save as source. Well, that's what it seems to me you just said. So why not cut out the middle man?
-
everything inside a single quote ' ' is interpreted literally. Variables and escape chars like \n for new line will echo out like you meant to write the name, not the value or instruction behind it. A common use for this is say...giving code examples. everything in a double quote " " is interpreted figuratively. PHP will recognize that when you put $blah you mean to put the value of $blah not the name of the variable. Or if you do like \n PHP knows that you mean to make a new line.
-
for your error: $show = $path . $file need a ; after $file also, include '$show'; single quotes will interpret $show literally you need to use double quotes " " for it to interpret it as a var
-
please do not make multiple threads asking the same question. I'm going to assume that this thread is a "narrowing down" of your last thread's problem, so I am closing your previous thread.
-
$list = mysql_query("SELECT value,title FROM $db_name"); change $db_name to your table name.
-
file_get_contents()
-
[SOLVED] function not working, need help please
.josh replied to jesushax's topic in PHP Coding Help
can you give example(s) of what $data is supposed to hold? -
yes. depends on where you're getting the page from. Pulling it from a database? I assume no, from earlier. Is it in a flatfile? Pulling it from some other site?
-
In your registration script, after the user's info is inserted into your database successfully, use the mail() function. p.s.- I find it hard to believe that you failed to find something from googling "php email"
-
By the way, I split up each foreach loop so you can better understand what's going on. You can mash all of those loops together: <?php // names that you got from a flatfile $textfile = 'data.txt'; if (file_exists($textfile) && is_readable($textfile)) { // read the file into an array called $users $users = file($textfile); } $content = "Here are a few names in my text file ben ryan and dave!"; // for each user in the array... foreach($users as $key => $val) { // trim off '\n' $users[$key] = trim($val); // make linked version $linkednames[] = "<a href='path/to/{$users[$key]}'>{$users[$key]}</a>"; // make pattern $pattern[] = "/{$users[$key]}/"; } // end foreach echo preg_replace($pattern, $linkednames, $content); ?>
-
ah okay I know what's going on. Since it's a text file, each line ends with '\n' which signifies the end of for editors it needs to be trimmed off in order for the preg_replace to work: <?php // names that you got from a flatfile $textfile = 'data.txt'; if (file_exists($textfile) && is_readable($textfile)) { // read the file into an array called $users $users = file($textfile); } // trim '\n' from each user foreach($users as $key => $val) { $users[$key] = trim($val); } // example string $content = "Here are a few names in my text file ben ryan and dave!"; // for each user in the array, make a new array with a linked version of the user foreach($users as $name) { $linkednames[] = "<a href='path/to/$name'>$name</a>"; } // in order to use preg_replace down there, you have to add / / around the name // to specify the start and end of the search string. so we're going to make an array // named pattern with the names like that. foreach($users as $name) { $pattern[] = "/$name/"; } // preg_replace accepts arrays as arguments. Basically it does all the hard work for you // internally it makes a loop to search through $content for each item in the $pattern array // and when it finds it, it replaces it with the item in the same key position as $linkednames // array. pretty nifty, huh? You can of course assign the results of preg_replace to a variable // instead of echoing it. echo preg_replace($pattern, $linkednames, $content); print_r($users); ?>
-
can you post the full relevant code? maybe you made a clerical error somewhere..
-
yes you can use php to generate an actual blah.jpg http://us2.php.net/gd
-
umm...do print_r($users); see if you really do have an array there...
-
minor bitch, but do..while loops are meant for conditions that don't have a set amount of iterations to them, or for when you don't know how many iterations there will be. If you know how many iterations there will be, use a for loop instead. It's a minor detail and having an outside $i var increment like that works too, but I mean, that's the point of a for loop for ($i = 1; $i < 135; $i++) { // code here } Just FYI, regardless of how you loop it, understand that php is a server side language. It will completely run its course before spitting things out to your browser. Depending on how much content is on those target pages, it may take a while to see some results, and your script may even time out. In a case like this, I would probably suggest using javascript to make a loop and send requests individually, instead.
-
well, using a regular flatfile with names on separate lines vs. a xml file is more a matter of preference. To be honest, since all you're wanting to do is take a chunk of text and search through it for a name, xml is probably overkill. I mean, you don't really need all the extra bells and whistles associated with using a xml file. Finding occurrences of the user's name in the chunk of text is the main trick here. It really depends on what's in that chunk of text, vs. how accurate you want it to be. Are you only wanting to link "valid" names? That is: You would of course want this: 1. I know this girl named Jane who... but, do you want it to link this? 2. I know this girl namedJanewho... Well anyways, here is an example. It does include making links like in #2... // example array of names that you got from a flatfile $users = array("Jane","John","Mike"); // example string $content = "I know this girl named Jane who likes this guy named John but John likes this guy Mike!"; // for each user in the array, make a new array with a linked version of the user foreach($users as $name) { $linkednames[] = "<a href='path/to/$name'>$name</a>"; } // in order to use preg_replace down there, you have to add / / around the name // to specify the start and end of the search string. so we're going to make an array // named pattern with the names like that. foreach($users as $name) { $pattern[] = "/$name/"; } // preg_replace accepts arrays as arguments. Basically it does all the hard work for you // internally it makes a loop to search through $content for each item in the $pattern array // and when it finds it, it replaces it with the item in the same key position as $linkednames // array. pretty nifty, huh? You can of course assign the results of preg_replace to a variable // instead of echoing it. echo preg_replace($pattern,$linkednames, $content);
-
1) this is 2 fold. If user is using correct username but wrong password, you can add an int type column to your user account table that increments each failed login attempt and then in your login processing script, add a condition to check that column and spit out a denial message if max attempts is reached. This doesn't really help if the username is wrong though, so part 2 would be to have another table called "failed_login_attempts" or something, in which you would pretty much do the same thing as before, except by ip address instead of username. That's about as best you can do, because even that would fail to implement a "3 strikes and you're out" policy, if they are using a proxy server or something (changing ip address). You would, of course, need to add some sort of way to have that column reset to 0. You could make the user contact someone who could manually do it if they can prove it's them. You could have it automatically reset after x amount of time. 2) This is also somewhat tricky. sessions are governed on the client, via a cookie. You don't really have control over what goes on with that, unless the user is making requests to the server, so if they login and then walk away from the computer, there's no way for you to automatically end that session on their end. However, if you're talking about having them being shown as "offline" like on a forum or something, you add a time type column in your user account table called "last_active" and another column type int called "status". When user logs in, change status to 1 (signifying they are "online.") "Users online: " query would be based on status being set to 1. Each time the user makes a request to the server, update it Setup a cron job to run every x time to check the current time vs. last_active and set status to 0 if it's more than x minutes and x seconds. 3) have a column in your user account table that holds their ip address. Each time a user logs in, update the ip address(using $_SERVER['REMOTE_ADDRESS']) . As long as they are considered "online (see #2), if another login attempt is made, check the status and ip and if it's set to 1 and ip don't match, then deny it.