Jump to content

Recommended Posts

Hi, i have been really annoyed with this for a while now, i am tring to replace only part of my text, but keep the middle bit in tact, e.g.

 

i want to replace

<img src="image.png" />

to:

[img=image.png]

I am aware this is BBCode but i am just trying to explain the problem, i am not very good at that :P

 

Thanks for any help, Scott.

Link to comment
https://forums.phpfreaks.com/topic/141843-solved-replace-part-of-a-piece-of-text/
Share on other sites

I tried to fix the problem by removing the two slashes inside the first bracket thingy, though i get an output, i get 2 < > on the outside?

 

$message = preg_replace('<img src="(.+?)" />','[img=$1]',"<img src=\"scott\" />");

goes to this:

<[_img]scott[_/img]>

**EDIT ALSO ADDED _ ON IMAGES FOR SAME REASON**

 

Its probably because i removed the slashes but that is the only way i could even get an output for message?

Any Suggestions?

 

Thanks, Scott

Hello Again, i have one last problem, is it possible to replace the string, even if it is not exact, i will use the same example because as i said, i can't explain things. Say i have an image,

<img src="scott" />

that works fine, but what if my image has parameters with it?  e.g.

<img src=scott" width="100px" height="100px" border="0">

^You know what i mean, it could have any number of differently ordered ones. e.g. height could come before width?

 

So is it possible to make this work using the same bbcode as above?  Even if it doesn't specify any parameters? - Just the URL to image? I only really care about height and width, though more would be good aswell, i already have the bbcode for this

[_img=100x100]image.png[/_img]

So is this possible?

 

Thanks for any help, Scott.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.