Skip to main content
Inspiring
August 26, 2006
Question

PHP String Replace

  • August 26, 2006
  • 17 replies
  • 773 views
I am looking to add my date to the beginning of my articles. Previously, I
was using the string replace function to look for the begininng of my
paragraph and then place the date in front of that. Bad Jon! I forgot that
any article with multiple paragraphs would then have multiple dates.

$artContent = str_replace('<p>', '<p> '.$artDateEdited.' - ',
$artContent);

So, what I am looking for is how do I do a string replaceon just the first
paragraph?

--

TIA,

Jon Parkhurst
PriivaWeb
http://priiva.net.


This topic has been closed for replies.

17 replies

Inspiring
September 8, 2006
No, but I should have an I am. I am using the TinyMCE javascript component
to add WYSWIG functionality. In addition to this, my input forms should do
a search and replace to ensure all paragraphs have the request tags.



Inspiring
September 8, 2006
Did he say he was using such a beast?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"Steve" <me@here.com> wrote in message
news:e2d2g25r67ehm03jo24d190r4b8ih5gv68@4ax.com...
> On Thu, 7 Sep 2006 18:22:13 -0400, "Murray *ACE*"
> <forums@HAHAgreat-web-sights.com> wrote:
>
>>Are you sure there are <p> tags in the data? The only way that could get
>>there would be if someone explicitly put them there.
>
> Rich text editors (like KTML or FCKEditor) convert user content into
> (X)HTML for insertion into the database.
> --
> Steve
> steve at flyingtigerwebdesign dot com


Inspiring
September 8, 2006
On Thu, 7 Sep 2006 18:22:13 -0400, "Murray *ACE*"
<forums@HAHAgreat-web-sights.com> wrote:

>Are you sure there are <p> tags in the data? The only way that could get
>there would be if someone explicitly put them there.

Rich text editors (like KTML or FCKEditor) convert user content into
(X)HTML for insertion into the database.
--
Steve
steve at flyingtigerwebdesign dot com
Inspiring
September 7, 2006
Are you sure there are <p> tags in the data? The only way that could get
there would be if someone explicitly put them there.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com - Template Triage!
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
http://www.macromedia.com/support/search/ - Macromedia (MM) Technotes
==================


"crash" <crash@bcdcdigital.com> wrote in message
news:edq4r8$db9$1@forums.macromedia.com...
> LOL, just now getting back to this.
>
> I've got myself in a little bit of a bind, b/c I didn't foresee my data
> having more than one paragraph.
>
> This is what I'm thinking of doing. If there's a better way, can somebody
> pipe in?
>
> Take data from database.
> Search for <p> tags, and capture all text within the first instances
> Limit text to X number of chars
> Replace <p> tags, and my ...Full Story links
>
> Looking now through all of the string functions and preg_replace right
> now.
>
> Basically, I"m having some problems finding a function that will replace
> $var on the Xth instance.
>
> Will post tomorrow with my results.
> "Joe Makowiec" <makowiec@invalid.invalid> wrote in message
> news:Xns982BA19BFAAE8makowiecatnycapdotrE@216.104.212.96...
>> On 26 Aug 2006 in macromedia.dreamweaver.appdev, crash wrote:
>>
>>> I am looking to add my date to the beginning of my articles.
>>> Previously, I was using the string replace function to look for the
>>> begininng of my paragraph and then place the date in front of that.
>>> Bad Jon! I forgot that any article with multiple paragraphs would
>>> then have multiple dates.
>>>
>>> $artContent = str_replace('<p>', '<p>
>>> '.$artDateEdited.' - ',
>>> $artContent);
>>>
>>> So, what I am looking for is how do I do a string replaceon just the
>>> first paragraph?
>>
>> http://www.php.net/manual/en/function.preg-replace.php
>>
>> In particular, the optional 4th parameter to preg_replace() is a limit;
>> you can set this to 1.
>>
>> --
>> Joe Makowiec
>> http://makowiec.net/
>> Email: http://makowiec.net/email.php
>
>


Inspiring
September 7, 2006
LOL, just now getting back to this.

I've got myself in a little bit of a bind, b/c I didn't foresee my data
having more than one paragraph.

This is what I'm thinking of doing. If there's a better way, can somebody
pipe in?

Take data from database.
Search for <p> tags, and capture all text within the first instances
Limit text to X number of chars
Replace <p> tags, and my ...Full Story links

Looking now through all of the string functions and preg_replace right now.

Basically, I"m having some problems finding a function that will replace
$var on the Xth instance.

Will post tomorrow with my results.
"Joe Makowiec" <makowiec@invalid.invalid> wrote in message
news:Xns982BA19BFAAE8makowiecatnycapdotrE@216.104.212.96...
> On 26 Aug 2006 in macromedia.dreamweaver.appdev, crash wrote:
>
>> I am looking to add my date to the beginning of my articles.
>> Previously, I was using the string replace function to look for the
>> begininng of my paragraph and then place the date in front of that.
>> Bad Jon! I forgot that any article with multiple paragraphs would
>> then have multiple dates.
>>
>> $artContent = str_replace('<p>', '<p>
>> '.$artDateEdited.' - ',
>> $artContent);
>>
>> So, what I am looking for is how do I do a string replaceon just the
>> first paragraph?
>
> http://www.php.net/manual/en/function.preg-replace.php
>
> In particular, the optional 4th parameter to preg_replace() is a limit;
> you can set this to 1.
>
> --
> Joe Makowiec
> http://makowiec.net/
> Email: http://makowiec.net/email.php


Inspiring
August 26, 2006
you da man Joe, thanks a million. :O)


"Joe Makowiec" <makowiec@invalid.invalid> wrote in message
news:Xns982BA19BFAAE8makowiecatnycapdotrE@216.104.212.96...
> On 26 Aug 2006 in macromedia.dreamweaver.appdev, crash wrote:
>
>> I am looking to add my date to the beginning of my articles.
>> Previously, I was using the string replace function to look for the
>> begininng of my paragraph and then place the date in front of that.
>> Bad Jon! I forgot that any article with multiple paragraphs would
>> then have multiple dates.
>>
>> $artContent = str_replace('<p>', '<p>
>> '.$artDateEdited.' - ',
>> $artContent);
>>
>> So, what I am looking for is how do I do a string replaceon just the
>> first paragraph?
>
> http://www.php.net/manual/en/function.preg-replace.php
>
> In particular, the optional 4th parameter to preg_replace() is a limit;
> you can set this to 1.
>
> --
> Joe Makowiec
> http://makowiec.net/
> Email: http://makowiec.net/email.php


Inspiring
August 26, 2006
On 26 Aug 2006 in macromedia.dreamweaver.appdev, crash wrote:

> I am looking to add my date to the beginning of my articles.
> Previously, I was using the string replace function to look for the
> begininng of my paragraph and then place the date in front of that.
> Bad Jon! I forgot that any article with multiple paragraphs would
> then have multiple dates.
>
> $artContent = str_replace('<p>', '<p>
> '.$artDateEdited.' - ',
> $artContent);
>
> So, what I am looking for is how do I do a string replaceon just the
> first paragraph?

http://www.php.net/manual/en/function.preg-replace.php

In particular, the optional 4th parameter to preg_replace() is a limit;
you can set this to 1.

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php