Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-29-2008, 10:06 PM Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Okay I am getting some out put from my application/script. that is entirely predictable in its pattern. I want to remove a few characters from it and replace them with spaces. any ideas.

Example output from my script

Code:
10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists (DM)��/dw�http://www.specialistsmod.net�http://www.specialistsmod.net�����������

10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists (DM)��/dw�http://www.specialistsmod.net�http://www.specialistsmod.net�����������
I would like to get rid of the ? and replace them with " " <- spaces

Where each ? represents an line break / new value from the server

I tried explode but with un desirable effects
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
 
Register now for full access!
Old 03-30-2008, 12:00 AM Re: Replace Characters?
dlaroche22's Avatar
Skilled Talker

Posts: 84
Name: Dustin Laroche
Trades: 0
I don't really understand what you are trying to do, but if im guessing right then using explode should work for you. I don't know what delimiter you used for explode, but I would give "?" a shot as a delimiter. So it would look like this:

PHP Code:
$data "
10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists (DM)��/dw�http://www.specialistsmod.net�http://www.specialistsmod.net�����������"
;

$holder explode"?"$data ); 
This will return an array with all the data divided by where the ? marks were at. So $holder[0] would equal 10.0.0.4:27015 and $holder[1] would equal "Jons POS Server". Then if you were wanting newlines you could use a loop to iterate through the array and output it to the screen. Hope this helps!
__________________
Under Construction, But A Work In Progress
Webhosting isn't cheap, sponsors are important

Please login or register to view this content. Registration is FREE
dlaroche22 is offline
Reply With Quote
View Public Profile
 
Old 03-30-2008, 10:20 AM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
What i am tryin to do is this

Above said data is collected from an active hlds server

this line generates said above output
PHP Code:
$status $this->RconCommand("\xFF\xFF\xFF\xFFTSource Engine Query\x00"); 
Have tried the following

PHP Code:
$test str_replace("?"," ",$status);
echo 
$test;
$testa explode("?"$status);
echo 
$testa[0]; 
All i want it done now is broken apart so it can be formated for the output
final output
Code:
Server Name  	
Current Map 	
Players 	/
Server Status 	Server Online
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 03-30-2008 at 10:22 AM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-31-2008, 07:03 AM Re: Replace Characters?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
$string = "10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists... bla bla";
$string = str_replace("�", " ", $string);
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 03-31-2008, 10:08 AM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
Quote:
Originally Posted by vectorialpx View Post
$string = "10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists... bla bla";
$string = str_replace("�", " ", $string);
when i tried the str_replace it dont work as expected. actually it dont work as it just shows the same formating.
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-31-2008, 11:09 AM Re: Replace Characters?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
<?php
$string = "10.0.0.4:27015�Jons POS Server�blackmarket_b4_v10�ts�The Specialists... bla bla";
$string = str_replace("�", "<br />\n\r", $string);
print $string;
?>

works fine to me

PS: the SPACE was just an example
__________________
you can
Please login or register to view this content. Registration is FREE

Last edited by vectorialpx; 03-31-2008 at 11:10 AM.. Reason: wrong BR :)
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 03-31-2008, 03:19 PM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
i think i found some of my problem

The parsed info to the browser is ? but it is is not an offical utf-8 format and is a special char. but I dont know what char is.

Is there a way to get the ascii char id or decimal format? so i can use that in the str_replace function.

Or is there to just echo the syntax out in its raw form with out being converted to characters?

the out put is a square instead of the ?

not to sound like a pia but the input is to get said about out put is "\xFF\xFF\xFF\xFFTSource Engine Query\x00" which is part hex, and the code coming back is also part hex

And php appears to be automaticly converting the returned packet when echoed to the browser. but when it is being altered in the script it is still in the hex form. So how would i start by converting it or finding all the hex values of each char on the return
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1

Last edited by amw_drizz; 03-31-2008 at 03:48 PM..
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-31-2008, 04:08 PM Re: Replace Characters?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
yeah... it's a ugly char
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 03-31-2008, 04:50 PM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
if it was a normal (ie all utf-8 chars) when php was processing it, it would be working. but since it is still in a hex form is why i am having issues.

So any way to convert the hex to a normal chars? so then it can be processed
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-31-2008, 05:06 PM Re: Replace Characters?
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
you have
$status = $this->RconCommand("\xFF\xFF\xFF\xFFTSource Engine Query\x00");

print htmlspecialchars($status);

what is this?
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Old 03-31-2008, 05:37 PM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
it seems to output the same data... still wont break it up correctly
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Old 03-31-2008, 06:36 PM Re: Replace Characters?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
the ? character is not really a question mark.
It's an UTF-8 character which current charset in use on your computer have no representation for.
So, searching for ? will not help you.

Proceed in those steps to determine what the character is:
1° Get the string in a variable.
2° For each characters of your string, call
PHP Code:
 echo ord($string[$position]); 
This will give you the ASCII value of the character.
3° When you have isolated the ASCII value, do a str_replace using chr($asciiNbr) as the character to look for

ord() reference: http://www.php.net/manual/en/function.ord.php
chr() reference: http://www.php.net/manual/en/function.chr.php
This should resolve your issue.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 03-31-2008 at 06:38 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-31-2008, 06:57 PM Re: Replace Characters?
amw_drizz's Avatar
Ultra Talker

Posts: 340
Name: Jon
Location: New York
Trades: 0
thanks tripy

that helped alot, in fact the ? was a null char. Problem solved, YES thank you

+rep
__________________
AMW_Drizz
Dev Machine:: Apache 2.2.6 PHP 5.2.6 MySQL 5.1
amw_drizz is offline
Reply With Quote
View Public Profile Visit amw_drizz's homepage!
 
Reply     « Reply to Replace Characters?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46588 seconds with 12 queries