473,466 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to replace characters in a string

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
2 3469
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
> <?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
4
by: Prasad S | last post by:
Hello I wish to replace all the characters in a string except those which are inside '<' & '>' characters. And there could be multiple occurences of < & > within the string. e.g. string =...
13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
3
by: o_swas | last post by:
Hello, I have a JavaScript string. I want to replace all consecutive occurrences of whitespace characters like spaces, tabs, newlines, and form feeds with another string. For example, say I...
9
by: David P. Donahue | last post by:
I'm using RegExp.Replace(string, string, string) to remove some pieces of large strings. But I seem to be having trouble getting it to match "all characters up to and including xxxxx" (which I...
9
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a...
5
by: djc | last post by:
I need to prepare a large text database field to display in an asp.net repeater control. Currently I am replacing all chr(13)'s with a "<br/>" and it works fine. However, now I also want to be able...
1
by: coolami4u | last post by:
I need a program that simulates the search-and-replace operation in a text editor. The program is to have only three function calls in main. The first function prompts the user to type a string of...
7
by: Grok | last post by:
I need an elegant way to remove any characters in a string if they are not in an allowed char list. The part cleaning files of the non-allowed characters will run as a service, so no forms here. ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.