PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 5th, 2012, 03:36 PM
BarackRommney BarackRommney is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 BarackRommney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 48 sec
Reputation Power: 0
Preg Match logic flaw

Hello everyone. I'm working on a madlib program for my web programming class but I'm very lost in replacing users input with my story. Here is my code so far, the last function is where it goes blank. I want the users to enter words and they get substitued with the patterns in my story.

PHP Code:
require "classfun.php";
printDocHeading("./index.css""assignment 4");
if(empty(
$_POST)) 
{
    
Storyselection();
}
else if(
$_POST)
{
    
Generateform();
}
else if(
$hide)
{
   
Displaystories();
}
printDocFooter();



function 
Storyselection()
{
  
$self $_SERVER['PHP_SELF'];
  print 
"<body>";
  print 
"<div class='content'>\n";
  print 
"<p> Pick a story! </p>";
  print 
"<form method='post' action='$self' >\n";
  print 
"<p> <input type='radio' name='story' value='1' /> \nFunny Story ".
    
"<input type='radio' name='story' value='2' /> \nSpooky Story ".
    
"<input type='radio' name='story' value='3' /> \nRegular Story ".
    
"</p>\n".
    
"<p> <input type='submit' name='submitStory' value='submitchoice'>\n".
    
"</p>\n".
    
"</form>\n".
    
"</div>\n";
}



function 
Generateform()
{
 
//print "<div class ='stor'>\n".
 //       "<h3> Enter the words into the forms </h3>\n".
  
  
print "<form method ='post' action= '$_SERVER[PHP_SELF]'>\n"
  
$story htmlentities($_POST['story']);
  
$filename2 ="story"."$story"."-"."$story".".txt";
  
$fh2 file_get_contents($filename2);
 
// print nl2br($fh2);
 // print "<p> here are the matches </p>";
  
$pattern "/\[(.+?)-(.+?)\]/";
  
preg_match_all($pattern,$fh2,$arrayOfMatches);
  for(
$i=0$i<count($arrayOfMatches[0]);$i++)
        {       
             
// print $arrayOfMatches[0][$i]."<br/>";
                
$desc $arrayOfMatches[2][$i];
                
$name $arrayOfMatches[1][$i];
               print 
" <p>$desc <input type='text' name ='$name' value = 'sub' />\n"."</p>";
                
    
                
               
        }
 print
"<input type ='hidden' name ='story' value= '$hide' /> \n";
 print
"<input type='submit' name='submitStory' value='submitsubs'>\n".
                
"</form>";

  
//print "</div>\n";
 // print "<a href='".$_SERVER['PHP_SELF']."'>Back to Start</a>\n";
}

 
//  for($i=0;$i<count($matches[0]);$i++)
//     {$desc = $matches[2][$i];
//     $name = $matches[1][$i];
//      <form method ='post' action= '$_SERVER[PHP_SELF]'>;
//      <input ='text' name = '$name' value=' />;
//       <input type ='submit' name='submitsubs' value='submitstor'>";
//       <"input type = 'hidden' name = 'story' value= '$hide' /> \n";
//      // generate form and send hidden value 
//
//      loop to substiute entered data with patterns
//       $subject=preg_replace($pattern,$replacement,$subject)
//       $name = $matches[1][$i];
//       $pattern= "/\[$name-(.+?)\]/";
//       $replace =$_POST[$name];


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Displaystories()
{
   
//display origianl story
  
print "<div class ='stor'>\n".
        
"<h3> Here is the original Story </h3>\n".
        
"</div>\n";
 
$story htmlentities($_POST['$hide']);
  
$filename2 ="story"."$hide"."-"."$hide".".txt";
  
$fh2 file_get_contents($filename2);
  
$subject=preg_replace($pattern,$fh2,$arrayofMatches);
for(
$i=0$i<count($arrayOfMatches[0]);$i++)
        {       
             
// print $arrayOfMatches[0][$i]."<br/>";
                
$desc $arrayOfMatches[2][$i];
                
$name $arrayOfMatches[1][$i];
                
$pattern"/\[$name-(.+?)\]/";
                
$replace =$_POST[$name];
    
                
               
        }
  
 print 
nl2br($fh2); 

// display sub story


// return to start menu button
//print "<a href='".$_SERVER['PHP_SELF']."'>Back to Start</a>\n";
//
//  
}


//
//foreach($matches[0] as $match) {
//    print " $match <br />";
//  }
//  print "<h4>Here is the 1st group: </h4>";
//  foreach($matches[1] as $match) {
//    print " $match <br />";
//  }
//  print "<h4>Here is the second group: </h4>";
//  foreach($matches[2] as $match) {
//    print " $match <br />";
//  } 

[[ please use [php][/php] tags when posting PHP code --requinix ]]

Last edited by requinix : October 5th, 2012 at 03:46 PM.

Reply With Quote
  #2  
Old October 5th, 2012, 03:48 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,875 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 55 m 55 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
What are the contents of those story files? How do they indicate what words to add and where?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Preg Match logic flaw

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap