By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

how to replace characters in a string

P: n/a
hello,

i have a javascript function call that does not accept white space, so i use
in
php:

$b ="tekst met spatie en nog een spatie";
$a = str_replace(" ","|",$b);

$a is sent as a parameter in the javascript function.
this works fine.

now i want in javascript to change the '|' sign back to white space.
so instead of 'tekst|met|spatie|en|nog|een|spatie' i want 'tekst met een
spatie en nog een spatie' again.

thanks

------------ source ----------------
<html>
<head>
<script type='text/javascript'>
function mijnFunctie(tekst){
window.opener.document.getElementById('invoerveld' ).value = tekst;
}
</script>
</head>
<body>
<?
$b ="tekst met spatie en nog een spatie";
$a = str_replace(" ","|",$b);

echo "<a href=javascript:mijnFunctie('" . $a . "')>verstuur</a>";

?>

</body>
</html>

-----------------------------------------------------



Oct 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 12/10/2005 16:07, nescio wrote:
i have a javascript function call that does not accept white space,
so i use in php:
[snip]
echo "<a href=javascript:mijnFunctie('" . $a . "')>verstuur</a>";
The problem here would seem to be your invalid markup, not the script.
You should always quote attribute values unless you understand when they
aren't necessary.

<?php
$text = 'tekst met spatie en nog een spatie';
?>
<a href="some-resource"
onclick="mijnFunctie('<?php echo $text; ?>'); return false;"verstuur</a>


Don't use the javascript: pseudo-scheme. See
<URL:http://www.jibbering.com/faq/#FAQ4_24>.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 12 '05 #2

P: n/a
> <?php
$text = 'tekst met spatie en nog een spatie';
?>
<a href="some-resource"
onclick="mijnFunctie('<?php echo $text; ?>'); return false;"
>verstuur</a>


Don't use the javascript: pseudo-scheme. See
<URL:http://www.jibbering.com/faq/#FAQ4_24>.


hello michael,

it works great,
thanks for your help and advice
Oct 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.