replaceing text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

sorry
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

well anyone
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

What are you asking again?
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

ok if you saw the post of the code it wille replace the text on my blog but i dont know a way to make an array for the posts and and comments sectuon because there are not only one


ok if you look at the that the blog templete they have something common at the part that it array they show
<!-- Begin .post -->
and then
<!-- End .post -->
so if some one could figure like a loop but first look for <!-- Begin .post --> then <!-- End .post --> then it could like section out the code on that make a array with a loop


but what would i use to section out that strand of code in <!-- Begin .post --> and <!-- End .post -->

sorry for spelling
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

look at:

Code: Select all

strtok()
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

ok that didnt work but i found another function called split

ok one more queston
is there a function out that will seach for a word and then add text to the end of that word that the function found

thank you so far
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

michael1991j wrote:is there a function out that will seach for a word and then add text to the end of that word that the function found
Not in a single function no. It will require a few functions combined.
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

like
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'll be blunt: I'm not here to hold your hand, nor do I think you want to be dragged through the code. So here's the functions that would be mostly involved: http://php.net/strings

Try figuring it out first. Show us what you've come up with. We'll go from there.
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

here is what i came up with

http://www.licut.com/blog/templates/cit ... p?blogid=1
it is better in I E
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not seeing any code.. just a lot of <$> all over... what are we supposed to be seeing here?

You've got private messages waiting.
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


that is what i have right now  i have left out the query and all that  but that is the main codeing

Code: Select all

<?php 

ob_start(); 

include('d.htm'); 

$pageHTML=addslashes(ob_get_contents()); 

ob_end_clean(); 


eval("\$pageHTML=\"$pageHTML\";"); 

 
$b = str_replace('<div class="entry" id="post-<$>">', '~<div class="entry" id="post-<$>">',$pageHTML);
$a = str_replace("
<ItemPage>
  
<BlogItemCommentsEnabled>"," 
 ~
<ItemPage>
  
<BlogItemCommentsEnabled>",$b);
$date = $a;
list($month, $d, $year) = split('[~]', $date);
echo $month;

do { 
$c = str_replace("<$BlogItemTitle$>",$row_post['posttitle'],$d);
$e = str_replace("<$BlogItemBody$>",$row_post['entry'],$c);
echo $c;
} while ($row_post = mysql_fetch_assoc($post));
echo $year;



?>






i am having trouble the str_replace function it is is replaceing the ones that are close and not exacted for instsance
$c = str_replace("<$BlogItemTitle$>",$row_post['posttitle'],$d);
it is supose to replace <$BlogItemTitle$> but it is replace the ones that are close to

!!! like <$BlogItemBody$>
how do you make it replace the one that are exact and not close
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yikes.

Code: Select all

ob_start();

include('d.htm');

$pageHTML=addslashes(ob_get_contents());

ob_end_clean();


eval("\$pageHTML=\"$pageHTML\";");
can, and should be, reduced to

Code: Select all

$pageHTML = file_get_contents('d.htm');
Stay away from eval(). It wasn't even necessary in your code to begin with.

Split() is a regular expression function (using POSIX no less.) Your code doesn't require the power of regex as yet, so explode() is a better choice. If you feel you want/need regex, use preg_split().

There is a logical error in how you've used a minus sign for the splitting key. Specifically, you've got minus signs in the div from your first call to str_replace(). I could suggest placing the splitting string into the source html file as say, an HTML comment like

Code: Select all

<!-- CUT HERE -->
Next, unless $BlogItemBody is an actual variable, I'd switch that string to a single quote one. Why? Because php will attempt to find such a variable. If it doesn't, it will fire an internal error. You may not see it, but that does not mean it doesn't happen. Now, since you've chosen to remove a section of code, it's hard to say if your logic for using a do..while over the more standard while was a good choice or not. I can only assume that you have already called mysql_fetch_assoc() once (or more) already to retrieve the first record to be shown.
User avatar
michael1991j
Forum Commoner
Posts: 37
Joined: Tue Jun 06, 2006 8:48 pm

Post by michael1991j »

that comment idea wont work because this is a paraphaser. so it is can read any of the blog templates at http://blogger-templates.blogspot.com/

i built this phaser so i dont have to edit the template .

havent you read the first post

but thank with the heads up with that eval and shortaning my code

feyd | michael. You bump this thread again and I'll be forced to lock it. You've already attempted to bump three times since joining this forum. That's not a good way to get on the nice side of the moderators or our community. Have patience.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

~michael1991j.... you've been warned about bumping enough times now. We've had to delete a couple of posts and we've prompted you to read your private messages. It's simple... don't bump. We don't like it, it's rude and it's unfair on everybody else waiting patiently for threads to be answered. This warning would have been easier to issue via PM but since you apparently don't check your PMs when asked here is your warning.

Thank you,

d11
Post Reply