Search code examples
phpsql.htaccessstr-replacefwrite

Textarea line break no working properly


I have a best problem in my experience, I want to write .htaccess file by fwrite(), when it debug its show ok in side the textarea but when I going to submit that then it show \n\r\n\r.... I was try str_replace() and its work but that does not break line. This is my all codes, please help me.

submit.php

<?php

//.htaccess file write and rewrite query

$file = ".htaccess";

$submit7 = $_POST['submit7'];

$edit = mysql_real_escape_string(str_replace( array("\r\n", "\n"), " ", $_POST['edit']));




function wee() {

    echo "<IfModule mod_rewrite.c> \n
\n RewriteEngine on \n";

    require('config2.php'); $getquery=mysql_query("SELECT * FROM menu ORDER BY menu_id DESC"); while($rows=mysql_fetch_assoc($getquery)){$menu_id=$rows['menu_id']; $linkname=$rows['linkname'];

echo "\n RewriteRule ^".$linkname."/{0,1}$  pagee.php?menu_id=".$menu_id. "[QSA,L] \n"; }

    echo "\n </IfModule>";



} 




    if ($submit7) {
    if ( is_writable( $file ) ) {
        // is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
        $f = fopen( $file, 'w+');
        if ( $f !== false ) {
            fwrite( $f, $edit );
            fclose( $f );

        }
    }
}



?>





<form id="form7" name="form7" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
      <label>
        <input type="submit" name="submit7" value="Write" />
      </label>

<textarea name="edit"><?php echo wee(); ?></textarea>



    </form>

config2.php

<?php

mysql_connect("localhost","root","");
mysql_select_db("myweb");


?>


<?php
$con = mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db ("myweb");
?>

sql.sql

--
-- Database: `myweb`
--

-- --------------------------------------------------------

--
-- Table structure for table `menu`
--

CREATE TABLE IF NOT EXISTS `menu` (
  `menu_id` int(11) NOT NULL,
  `mname` text NOT NULL,
  `level` text NOT NULL,
  `linkname` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `menu`
--

INSERT INTO `menu` (`menu_id`, `mname`, `level`, `linkname`) VALUES
(1, 'Home', 'home', 'aaaa'),
(2, 'Music', 'Music', 'Music'),
(3, 'Movie', 'Movie', 'Movie'),
(4, 'Song', 'Song', 'Song');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `menu`
--
ALTER TABLE `menu`
  ADD PRIMARY KEY (`menu_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `menu`
--
ALTER TABLE `menu`
  MODIFY `menu_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

.htaccess --- output result now showing

<IfModule mod_rewrite.c>  RewriteEngine on  RewriteRule ^Song/{0,1}$  pagee.php?menu_id=4[QSA,L]  RewriteRule ^Movie/{0,1}$  pagee.php?menu_id=3[QSA,L]  RewriteRule ^Music/{0,1}$  pagee.php?menu_id=2[QSA,L]  RewriteRule ^aaaa/{0,1}$  pagee.php?menu_id=1[QSA,L]  </IfModule>

But I want that like this:

<IfModule mod_rewrite.c>  

RewriteEngine on  

RewriteRule ^Song/{0,1}$  pagee.php?menu_id=4[QSA,L]
RewriteRule ^Movie/{0,1}$  pagee.php?menu_id=3[QSA,L]  
RewriteRule ^Music/{0,1}$  pagee.php?menu_id=2[QSA,L]  
RewriteRule ^aaaa/{0,1}$  pagee.php?menu_id=1[QSA,L]  

</IfModule>

Please Please Please HELP ME......


Solution

  • OK Dear I think I find you result just do that replacement ok,

    submit.php

    <?php
    //.htaccess file write and rewrite query
    
    $file = ".htaccess";
    $submit7 = $_POST['submit7'];
    
    if ($submit7) 
    {
       $htfe = file_put_contents('.htaccess', $_POST['edit']);
    }
    
    function wee() 
    {
        echo "<IfModule mod_rewrite.c> \n
        \n RewriteEngine on \n";
        require('config2.php'); $getquery=mysql_query("SELECT * FROM menu ORDER BY menu_id DESC"); while($rows=mysql_fetch_assoc($getquery)){$menu_id=$rows['menu_id']; $linkname=$rows['linkname'];
        echo "\n RewriteRule ^".$linkname."/{0,1}$  pagee.php?menu_id=".$menu_id. "[QSA,L] \n"; }
        echo "\n </IfModule>";
    }
    ?>
    
    <form id="form7" name="form7" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
          <label>
            <input type="submit" name="submit7" value="Write" />
          </label>
          <textarea name="edit"><?php echo wee(); ?></textarea>
    </form>
    

    I thing you should get you solution, ok Just change this file submit.php ok