Mohammed H Mohammed H - 6 months ago 28
PHP Question

Wordpress auto post script

hi i've find this script, it works when i use normal charcter but when i try to insert some special chars doesn't work i tried json escape no luck can some one help me what's wrong ?
get error

PHP Parse error: syntax error, unexpected 'http' (T_STRING) in /var/www/html/auto_post.php on line 20

<?php


require( 'wp-load.php' );
function simpleImportPost($title,$import_id,$content){
// Create post object
$my_post = array();
$my_post['post_title'] = $title;
$my_post['import_id']=$import_id;
$mypost['comment_status'] = 'closed';//I'll set all closed
$my_post['post_content'] = $content;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['post_category'] = array(0);
// Insert the post into the database
return wp_insert_post( $my_post );
}

$ch_name="Live_tv_1";
simpleImportPost("$ch_name",35,"<iframe src="http://site.xxx/jwplayer_6/elchourouk.html" style="width: 640px; height: 480px" scrolling="no" frameborder=0 ALLOWTRANSPARENCY="true" overflow:hidden; ></iframe>");


?>

Answer

Do you notice how

simpleImportPost("$ch_name",35,"<iframe src="http://site.xxx/jwplayer_6/elchourouk.html" style="width: 640px; height: 480px" scrolling="no" frameborder=0 ALLOWTRANSPARENCY="true" overflow:hidden; ></iframe>");

includes many " which even the display here can't parse correctly?

When you want to embed quotes inside other quotes, you either use different quotes (' vs ") or escape them with a backslash (\) such as:

simpleImportPost("$ch_name",35,"<iframe src='http://site.xxx/jwplayer_6/elchourouk.html' style='width: 640px; height: 480px' scrolling='no' frameborder=0 ALLOWTRANSPARENCY='true' overflow:hidden; ></iframe>");
Comments