Text line not working normally

I have the best problem in my experience, I want to write a .htaccess file via fwrite () when it debugs its ok show in the side of the textarea, but when I go to imagine then it shows \ n \ r \ n \ r. ... I tried str_replace () and it worked, but it doesn't break. These are 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 shows

<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 it 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 HELP ME ...

+3


source to share


2 answers


OK Dear, I think what I find is that the result is just doing this 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 want you to get a solution, ok Just change this file submit.php

ok

+1


source


Four solutions:

1) Use PHP nl2br () function

eg.

echo nl2br("This\r\nis\n\ra\nstring\r");

// will output
This<br />
is<br />
a<br />
string<br />

      


2) Wrap the input with a tag <pre></pre>

.

See: http://www.w3.org/wiki/HTML/Elements/pre




3) Use
$textToStore = nl2br(htmlentities($inputText, ENT_QUOTES, 'UTF-8'));

      




4) Use
file_put_contents('.htaccess', $_POST['textarea_value']);

      

file_put_contents()

combines the functions of fopen

, fwrite

,fclose

+3


source







All Articles