alexville Posted March 15, 2007 Share Posted March 15, 2007 I'm not sure if this is possible, but is there a way were you can take all the " out of a variable and replace it with ' ? Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/ Share on other sites More sharing options...
kenrbnsn Posted March 15, 2007 Share Posted March 15, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208349 Share on other sites More sharing options...
alexville Posted March 15, 2007 Author Share Posted March 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208354 Share on other sites More sharing options...
papaface Posted March 15, 2007 Share Posted March 15, 2007 What do you mean "make this code work in PHP" ? Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208357 Share on other sites More sharing options...
alexville Posted March 15, 2007 Author Share Posted March 15, 2007 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. Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208359 Share on other sites More sharing options...
Lumio Posted March 15, 2007 Share Posted March 15, 2007 <? 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208360 Share on other sites More sharing options...
alexville Posted March 16, 2007 Author Share Posted March 16, 2007 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 Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208765 Share on other sites More sharing options...
effigy Posted March 16, 2007 Share Posted March 16, 2007 Please review strings. Not only are the quotes unnecessary, but single quotes do not interpolate variables. Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208785 Share on other sites More sharing options...
virtuexru Posted March 16, 2007 Share Posted March 16, 2007 You need to slash them out... For example Say you want to output: <a href="blabla.com">here</a> You would need to do this.. echo "<a href=\"blabla.com\">here</a>"; Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-208834 Share on other sites More sharing options...
alexville Posted March 16, 2007 Author Share Posted March 16, 2007 Is their a script or a function that will do that when someone inputs data into a form and posts it to php? Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-209119 Share on other sites More sharing options...
fert Posted March 16, 2007 Share Posted March 16, 2007 http://us3.php.net/manual/en/function.addslashes.php Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-209183 Share on other sites More sharing options...
alexville Posted March 17, 2007 Author Share Posted March 17, 2007 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> Link to comment https://forums.phpfreaks.com/topic/42898-change-characters-in-a-variable/#findComment-209456 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.