chinto09;10890522 wrote:thank you nrg_alpha.
It is working but it is creating problem as well.
Because i have 30 other news on the same page.
What this code is doing is replacing all the images with this single one and replacing all the headline with this sinlle headline news. π
Actually i want to target a single news heading and its respective image.
here is code again
//these value will come from a html form
$new_img=$Post['new_img'];
$heading=$Post[''heading'];
$news_no=$_Post[''news_no'];
suppose i want to change news number 25 then
$new_img='news_25.jpg';
$heading='News no. 25 heading';
$news_no='eng25.html';
//input target string
$string=<img src="images/pirzada.jpg" alt="" border="0" align="left">
<a href="news/eng25.html"><strong>
i am news 25 headline
</strong>
$replace=<<<BEGIN
<img src="images/$new_img" alt="" border="0" align="left">
<a href="news/$news_no"><strong>
$hading
</strong>
BEGIN;
//pattern is needed
$pattern=
preg_replace($pattern, $replace, $string);
I won't have enough time to help out on the rest... I did want to make a note on your coding though..
By example, you have two single quotes on one side in your $POST variable?
$news_no=$Post[''news_no'];
Be consistent and use sinlge quotes:
$news_no=$_Post['news_no'];
Your $string is not surrounded by single quotes:
$string=<img src="images/pirzada.jpg" alt="" border="0" align="left">
<a href="news/eng25.html"><strong>
i am news 25 headline
</strong>
Should be:
$string='<img src="images/pirzada.jpg" alt="" border="0" align="left">
<a href="news/eng25.html"><strong>
i am news 25 headline
</strong>';
I'm not sure why in your replace, you are using the heredoc (<<<BEGIN and BEGINπ.
And now you are adding a new part to the problem:
<a href="news/$news_no"><strong>
You should list everything you need upfront.. this would have saved some time trouble shooting this thing.
As far as all images and headers being replaced by the same one, you will need to make your $new_img, $heading and $news_no variables as arrays instead of being single valued variables.