Forum Thread
  Posts  
[PHP]Some help..not hard (Forums : Coding & Scripting : [PHP]Some help..not hard) Locked
Thread Options
Apr 14 2003 Anchor

I hope this belongs in Tech Support. Anyhow, I'm really new at PHP, and I've decided to ditch trying to learn SQL.. all those programs aren't working for me. I like a programming language, not a ton of executables and stuff.

Okay, now for the thing. I want to change all spaces in a string to plus signs '+'. Don't tell me oh, the browser changes them to %20 anyway, I just want to know how to replace stuff in a string.

If you have a string called $pie, can you access individual characters like in C? For instance:

$pie = "I LIEK PIE";
then
($pie[3] == 'I')

also, Intense said there was no data type casting in PHP, but some tutorial had this!
srand ((double) microtime () * 1000000);

That looks like casting to me!

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 14 2003 Anchor

pretty sure u can do it... strreplace, or somethin like that... its one of the str commands, look at php.net s list of commands...

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 14 2003 Anchor

Okay, thanks, str_replace replaces all occurrences of a string in another string. I guess I could use one-character strings, yes :) Thank you pf, you are definitely not the person I was expecting an answer from!

But there are still parts 2 and 3 of my first post in effect :D

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 14 2003 Anchor

dunno, thats as far as i got in php :P

it confused the hell out of me, considering i have no background in any formal coding outside of html

i remember something that did this though....

substr_replace perhaps?

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 14 2003 Anchor

Ha, html isn't format coding. Maybe xhtml is though

No, str_replace does it fine.

By the way, the Fniggium site has been completely PHPized!

But there are still parts 2 and 3 of my first post in effect

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 14 2003 Anchor

A hundred years ago, a big monster came and ate people and a hero emerged and chosen one and kill monster and save earth and now more monster and now your turn and you are now chosen one and you have to be hero and kill ten thousand monsters and become powerfullest person in world.

indeed...

btw, what were the other things u wanted to know?

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 14 2003 Anchor

SeienAbunae wrote: If you have a string called $pie, can you access individual characters like in C? For instance:

$pie = "I LIEK PIE";
then
($pie[3] == 'I')

also, Intense said there was no data type casting in PHP, but some tutorial had this!
srand ((double) microtime () * 1000000);

That looks like casting to me!

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 14 2003 Anchor

i believe you can... what are u trying to do with it?

there is a command that is used for replacing letters with the foreign characters that sounds like what u want

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 15 2003 Anchor

Yeah, strtr() I think.

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 15 2003 Anchor

i believe that individual characters are accesible, but it depends on what u want to do with them... there might be certain things that u cant do...

i sorta have a vague idea about what im talking about, but i dont have anywhere to play around with it, so i dont know how to actually implement these things... i have a questiong also about php, will post in a different thread

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

Apr 15 2003 Anchor
$news->info = eregi_replace("(^|[>[:space:]\n])([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])([<[:space:]\n]|$)","\\1<a href=\"\\2://\\3\\4\" target=\"_parent\">\\2://\\3\\4</a>\\5", $news->info);
$news-&gt;info = eregi_replace(&quot;\\[img\\]([^\\[]*)\\[/img\\]&quot;,&quot;<center>&lt;img src=&#039;\\1&#039; border=&#039;0&#039;&gt;</center>&quot;, $news-&gt;info);
$news-&gt;info = nl2br($news-&gt;info);
$news-&gt;info = parseCode($news-&gt;info);
$news-&gt;infolong = nl2br($news-&gt;infolong);
$news-&gt;infolong = parseCode($news-&gt;infolong);

or

function parseCode($StrData)
{$StrData =str_replace(array(&quot;:)&quot;,&quot;:D&quot;,&quot;:(&quot;,&quot;:S&quot;,&quot;:o&qu
ot;,&quot;xD&quot;,&quot;;)&quot;,&quot;:P&quot;),
array(&quot;&lt;img src=&#039;images/smilies/smile.gif&#039; title=&#039;Smile&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/bigsmile.gif&#039; title=&#039;Big grin&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/sad.gif&#039; title=&#039;Sad&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/curly.gif&#039; title=&#039;Ermmm&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/shocked.gif&#039; title=&#039;Shocked&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/mad.gif&#039; title=&#039;Angry!&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/wink.gif&#039; title=&#039;Wink&#039;&gt;&quot;,
&quot;&lt;img src=&#039;images/smilies/tongue.gif&#039; title=&#039;*sticking tongue out*&#039;&gt;&quot;,),$StrData);
return $StrData;}

--

Why wont it save me?

jacksonj04
jacksonj04 Over 9000
Apr 15 2003 Anchor

what azzyman said. And this should be in coding methinks...

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

Apr 15 2003 Anchor

Your first code sample makes little sense to me, azz0r, but thank you for the second one! I'll look eregi_replace on php.net (a handy site indeed).
I've basically been going off of tutorials from Onnovanbraam.com (click resources), and that's pretty sad. I learned how to read from a directory and do arrays and stuff there. And I also searched for a tutorial on how to get random numbers.

Now, my site has interesting features. The screenshots page lists all files in the images/screenshots/ directory and displays their thumbnails by adding thumbs/ at the end of the directory name. And then, the front page displays four random images from that folder in the center column! Neato, except I don't have any screenshots right now.
The front page also has a news thing, where you give it a big array with all the news posts where array element [0] is the oldest. There is a variable for picking how many posts appear on the first page ($newsonfrontpage), and it displays the newest first on the page. Then, if all posts aren't being shown (read, $newsonfrontpage isn't set to like 30 or something), it makes a 'View old news' link, that goes to a variation of the page (/?section=index&oldnews=1) that shows the rest of the news.
Then, the Concept Art, Files, and Team pages work off big arrays in the PHP files as well. For stuff like Concept Art, I'd like to just read stuff out of the directory like screenshots, but the images have names, authors and descriptions so I use arrays.
Remember, I don't want to get into MySQL or anything.

If you want to check out the code, see the the following code.
Here's the source to index.php:
Fniggium.actionrealm.com

And then check out the following text files for the code I am so proud of because I'm completely new to PHP! And I only used tutorials to figure out what functions I need to do stuff like get random numbers and read from a directory. And figure out the basic language structure for stuff like variables and arrays.

Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com
Fniggium.actionrealm.com

I suppose I could rename these files to PHP or something so you wouldn't be able to read the source or something, but there's nothing in there that I want hidden. Feel free to look around and critique/suggest/advise/flame/worship me for it!

- Edited By SeienAbunae On Tue 15th, Apr 2003 @ 6:52:31pm

- Edited By SeienAbunae On Tue 15th, Apr 2003 @ 6:53:33pm
- Edited By SeienAbunae On Tue 15th, Apr 2003 @ 6:56:05pm

--

User Posted Image

PsychoFarmer
PsychoFarmer modDB King
Apr 15 2003 Anchor

since i really have no idea what that means, erm, its good O_o

--

___________________________
Today seems like a good day to burn a bridge or two
I am the freakiest man in the world!!!!
I beg to differ, on the contrary, I agree with every word that you say

User Posted Image

jacksonj04
jacksonj04 Over 9000
Apr 16 2003 Anchor

looks nice

--

Barcode Imagejacksonj04 the generally helpful one
Lost, confused or just need a virtual cuddle? PM me.
Need urgent help from staff? PM us all.

INtense!
INtense! End Boss
Apr 16 2003 Anchor

you can easily get any character out of a string i.e.

$string = 'hello';

then

echo $string{3};

would output 'l'

as for your other question, in PHP you do not have to data cast any variables, and you can change between them as you please, however occasionally it is needed as you cannot order a string of numbers for example

--

Scott Reismanis
DBolical | @scottreismanis

Apr 16 2003 Anchor

$ThemeName = (strtoupper(substr($Theme,0,1)).substr($Theme,1));

Will capitalise $Theme

Wuggawoo.co.uk
Wuggawoo.co.uk
Wuggawoo.co.uk

--

Why wont it save me?

Apr 18 2003 Anchor

A PHP equivalent of itoa() maybe?

Thanks for the help Intense! So you have to use curly braces {} instead of square brackets []? I guess strings aren't really treated as arrays then...

--

User Posted Image

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.