0

Hi all,

I'm trying to get the content of a div with php. I can't find a way to use javascript in php to do it so I was thinking that regex would be the way?

If it helps the div id is "editor".

Thanks in advance, if you need anything more then just ask.

5
Contributors
14
Replies
20
Views
7 Years
Discussion Span
Last Post by leegeorg07
0

You can use Javascript in PHP in the following way:

<?php
		for($i=0; $i<20; $i++)
	{?>
	<script type = 'text/javascript'>
		var hp="<?php echo $i; ?>";
		alert (hp);
		</script>
	<?php
	}
	?>
0

okay, so could I use

<?php
    $content=
?>
<script type = 'text/javascript'>
    document.getElementById("editor");		
</script>
<?php
    ;
?>

?

Thanks for the speedy reply by the way.

0

Hi all,

I'm trying to get the content of a div with php. I can't find a way to use javascript in php to do it so I was thinking that regex would be the way?

If it helps the div id is "editor".

Thanks in advance, if you need anything more then just ask.

Are you aware that PHP also has a DOM class?
check it out here:
http://us3.php.net/manual/en/book.dom.php

0

@estevemd is it possible to use jquery in php or to pass a jquery variable to php then?

0

Nothing special. It is just Javascript library that simplifies things. And yes it can play with PHP very well. What specifically you want to do? You might find it already full implemented there
see this example though a little complex

0

Thanks, I did a bit of research and I now have a working piece. but I'm having a problem with writing the data to a text file. I have this js code:

<script type = 'text/javascript'>
	var b=document.getElementsByTagName("editor");		
    	$.post("write.php", {"text": b});
</script>

and write.php is:

<?php
	$data = $_POST["text"];
   	$myFile = "testFile.txt";
	$fh = fopen($myFile, 'w') or die("can't open file");
	fwrite($fh, $data);
	fclose($fh);
?>

but when I open the file locally it is a blank file, can you offer any advice?

Edited by leegeorg07: n/a

0

Scratch that last post, I have fixed the original problem, but I found a new one after fixing it, is says parse error in line 2 of the code below. any help?

<?php
	$data = $_REQUEST"text"];
   	$myFile = "testFile.txt";
	$fh = fopen($myFile, 'w') or die("can't open file");
	fwrite($fh, $data);
	fclose($fh);
?>

Edited by leegeorg07: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.