Jump to content

Change Characters in a variable


alexville

Recommended Posts

Use the str_replace function.

<?php
$str = 'this string has double quotes " " " in it';
$str = str_replace('"',"'",$str);
echo $str;
?>

 

If you explain why you want to do this, perhaps there is another solution to your problem.

 

Ken

I want people to be able to input data into my website say, maybe from YouTube.

 

Here is the data:

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ECM9N7jrA0o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ECM9N7jrA0o" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

 

I have to make this code work in PHP, not HTML.

If I did this code:

<?
echo "<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ECM9N7jrA0o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ECM9N7jrA0o" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>";
?>

 

It wouldn't work because of the quotes.

<?
echo '<p><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ECM9N7jrA0o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ECM9N7jrA0o" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
?>

or

<?
echo "<p><object width=\"425\" height=\"350\">...</object>';
?>

I can't get it to work with a variable. This is my code:

 

<?
$text = $_POST['text'];

echo '$text';

?>

 

The user inputs this :

<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/ECM9N7jrA0o"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/ECM9N7jrA0o" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

 

And this is what comes out of it:

 

$text

I still can't get it to work. Can someone help me fix this code, so that the video will show?

 

-- TEST1.PHP

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="test2.php">
  <p>
    <input name="text" type="text" id="text">
</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

 

--- text2.php

 

<? 
/* Include Files *********************/
session_start(); 
include("database.php");
include("login.php");
/*************************************/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?
$text = $_POST['text'];

echo addslashes($text);

?>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

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