strange requirement with PHP

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

Post Reply
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

strange requirement with PHP

Post by hemanshurpatel »

hello friends,
i have recently started coding PHP, so i am still at beginners stage, so please bear me if you found this very silly question.

What i want is to add a particular code after say first 100 characters in my post.

say i have a post of 1000 words and after initial say 100 words i want to add a new tag of ream more, that tag is <!--more-->.
so after first 100 characters this tag should come and then the rest of post should.
so is there any function in PHP which let me allow few words in somewhere middle of any post?

Waiting for the reply and thanking of you in advance.

Regards,

Hemanshu Patel
http://www.tutorialsforu.info
http://www.articlesdir.co.cc
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: strange requirement with PHP

Post by requinix »

You can use substr_replace with a $length of zero...
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

Re: strange requirement with PHP

Post by hemanshurpatel »

i think you didnt get my problem

how can use substr_replace
i dont know what i need to replace with, as i dont know what word it will be at the end of 100 characters.
semlar
Forum Commoner
Posts: 61
Joined: Fri Feb 20, 2009 10:45 pm

Re: strange requirement with PHP

Post by semlar »

Okay, you've said two very different things in your post, so if you could just clear up whether you want to insert your text after the 100th character or the 100th word that would help immensely. I'm assuming you mean characters, because that makes more sense.

Here's an example for using substr_replace..

Code: Select all

<?php
$string = "1234567890";
echo substr_replace($string,'[!-- example --]',5,0);
?>
Outputs

Code: Select all

12345[!-- example --]67890
You would just use something like substr_replace($string,'<!-- more -->',100,0)
hemanshurpatel
Forum Newbie
Posts: 6
Joined: Wed Sep 10, 2008 6:25 am

Re: strange requirement with PHP

Post by hemanshurpatel »

yeah, thats what exactly i want
let me try this
Post Reply